cant use laravel response on extended controllers

im using laravel and i want to put response()->json() in a method on laravel’s controller and calls it from extended controllers or make a __destruct method and put return response()->json() in it? this is my code in controller : class Controller extends BaseController { use AuthorizesRequests, DispatchesJobs, ValidatesRequests; protected function prepare_response(int $http_code , string $message…

Laravel Excel convert change date format

I’m trying to convert date with laravel excel, below is my code : <?php namespace App\Exports; use App\Project; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMapping; use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Maatwebsite\Excel\Concerns\WithTitle; use Maatwebsite\Excel\Concerns\WithEvents; use Maatwebsite\Excel\Events\AfterSheet; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use Maatwebsite\Excel\Concerns\WithColumnFormatting; class ProjectExport implements FromCollection, WithHeadings, WithMapping, ShouldAutoSize, WithTitle, WithEvents, WithColumnFormatting { public function collection() { return Project::with(‘developer_projects’)->get(); } //…

Laravel | Generate PDF file from Blade view. Data from relationship tables

I have two tables Pages and Subpages in relationship one to many. In Subpages table I have page_id which is associated with the pages table id. In my Page model I have: public function subpages(){ return $this->hasMany(Subpage::class); } In PageController, function generatePDF: public function generatePDF(PageRepository $pageRepo, $id) { $page = $pageRepo->find($id); $title = $page->title; $subtitle…

n Laravel, Cannot get user details in auth.basic

I tried this in routes/web.php but the result is null Route::get(‘swagger-yaml’, function () { dd(auth()->user()); }) ->middleware([‘auth.basic:web’]) I found the reason of the strange behaviour, that’s because in config/auth.php I have: ‘defaults’ => [ ‘guard’ => ‘api’, ‘passwords’ => ‘users’, ], But how can I fix that? For a series of reasons cannot change config/auth.php.

Call to a member function count() on int in Laravel?

I want to count the total number of new students created in this month and the number of online students in this month public function index () { $month = Carbon::now()->month; $members = Member::getStudents(); $saleareas = Member::getSaleAreas(); Order::getTotalCardOnSaleAreas($saleareas); foreach ($members as $member) { $newstudent = $member->created_at->month; $online = $member->updated_at->month; if($month == $newstudent){ $members = $members->count();…