Show an attribute from other model in blade (Laravel)

I´ve got this exception in my blade template. I made a relation between my two models (RegisteredCourses y User) and I can see it works in the rest of Blade´s template, except form.blade.php Trying to get property ‘user’ of non-object (View: C:\laragon\www\hr-english\resources\views\registeredCourse\form.blade.php) (View: C:\laragon\www\hr-english\resources\views\registeredCourse\form.blade.php) My idea is to show in my blade template the name…

How to get the type of the user in laravel?

I want the code to check if the current user category is admin or superadmin, it will show the edit panel @if (Auth::user()->category==’admin’||Auth::user()->category==’superadmin’) <td class=”center”> <a href=”” class=”btn btn-warning btn-sm custom”> <i class=”glyphicon glyphicon-edit”></i> EDIT</a> </td> else, it will display message like this @else <td class=”center”> <b><p>This is only for admin</p></b> </td> I have table…

How to get the type of the user in laravel?

I want the code to check if the current user category is admin or superadmin, it will show the edit panel @if (Auth::user()->category==’admin’||Auth::user()->category==’superadmin’) <td class=”center”> <a href=”” class=”btn btn-warning btn-sm custom”> <i class=”glyphicon glyphicon-edit”></i> EDIT</a> </td> else, it will display message like this @else <td class=”center”> <b><p>This is only for admin</p></b> </td> I have table…

Laravel eloquent taking 6-12 seconds to return results

I have this data I’m trying to pull, but I have a lot of rows in the DB (over 100k) so it can take 12 secs to return results. Any ideas on how to improve performance? $completedActivities = Activity::where(‘executed_at’, ‘>’, Carbon::now()->subDays(14)) ->where(‘pending’, false) ->where(‘user_id’, auth()->user()->id) ->orderby(‘executed_at’, ‘desc’) ->limit(100)->get(); Table structure: Schema::create(‘activities’, function (Blueprint $table) {…