"Serialization of 'PDO' is not allowed" Cache Error
When i run this code, it gives above error
MainCategoryController.php
public function index(Request $request)
{
$currentUserRole = Auth::user()->roles->pluck('name')->first();
if ($request->ajax()) {
if ($currentUserRole === "student") {
$userId = Auth::id();
//Get Assigned Users Courses
$userAssignedCourses = User::with(['courses' => function ($query) {
$query->with(['subCategory', 'mainCategory']);
}])->findOrFail($userId);
$userAssignedCourses = $userAssignedCourses->courses;
$data = $userAssignedCourses->pluck('mainCategory');
} else {
// $data = MainCategory::orderBy('id', 'desc');
$data = Cache::put('data', MainCategory::orderBy('id', 'desc'),config('cache.expire_time.short'));
}
.....
}
}
Specic User who are doing courses . that courses has sub category , main categories
Eg :
John learn english , Main Category is English , Sub Category is Batch 01
I'm talking about
$userId = Auth::id();
$userAssignedCourses = User::findOrFail($userId);
$userId = Auth::id();
$userAssignedCourses = User::find($userId);
Similar code. Get current Logged user id , and get his details
It's same as
Auth::user();
so
$userAssignedCourses = Auth::user()->load(['courses.subCategory', 'courses.mainCategory']);
Sorry. mistakenly it marked as a Right one .
Still i got this error
@ddsameera The error is here
$data = Cache::put('data', MainCategory::orderBy('id', 'desc'),config('cache.expire_time.short'));
is has to be
$data = Cache::remember('data', now()->addMinutes(10), function() {
return MainCategory::orderByDesc('id')->get();
});
You miss ->get().
Please or to participate in this conversation.