Category : laravel-query-builder

I’m still new to Laravel. I want to select the mainchallengecategories with field role_id on the table that holds the relationship that is equal to 3 because I want only the user who has role_id = 3 to see the mainchallengecategories. What should I do with my controller? I have 4 tables 1. mainchallengecategories id ..

Read more

I want to union table questions and choices in query builder JSON Resource laravel, when I’m trying this, I’m getting an error, what’s wrong with my code?, please give me some advice on this code This is my CurriculumDisplayResource <?php namespace AppHttpResources; use IlluminateHttpResourcesJsonJsonResource; use IlluminateSupportFacadesDB; class CurriculumDisplayResource extends JsonResource { public function toArray($request) { ..

Read more

This query works with group by $data = DB::select(DB::raw("SELECT SUM(pending) as total , datediff(NOW(), created_at) as maturity FROM `admin_case_info` WHERE deleted_at is NULL group by maturity ")); But when I joined 2 tables. $data = DB::select( DB::raw("SELECT admin_case_info.case_type, admin_case_info.case_status, SUM(admin_case_info.pending) as total, datediff(NOW(), admin_case_info.created_at) as maturity FROM admin_case_info JOIN users_mws on users_mws.id = admin_case_info.users_mws_id JOIN ..

Read more

I have a raw query that I want to convert into querybuilder since I need to modify it. Here is the old query SELECT mws_name, MAX(created_at) as created_at, updated_at, SUM(pending) as pending, SUM(approved) as approved, SUM(rejected) as rejected FROM ( SELECT um.mws_name, ac.users_mws_id, ac.case_type, ac.created_at, ac.pending, ac.approved, ac.rejected, ac.updated_at FROM admin_case_info ac JOIN users_mws um ..

Read more

I am making site with laravel and vuejs. I use complex Eloquent query for getting data from DB as follows. $query->with([ ‘deviceAssignment.deviceSetting.sim’, ‘deviceAssignment.deviceSetting.device.deviceType’, ‘deviceSignal’, ‘deviceAssignment.deviceSetting.deviceGroup’, ‘deviceAssignment.deviceSetting.company’, ‘deviceAssignment.deviceSetting.phones’]) ->orderBy(‘created_at’, ‘desc’) ->get(); I use several tables at once, then this size of data is somewhat huge, so I want to paginate this data. I placed paginator in ..

Read more

I am trying to build laravel auth api with sanctum and I followed the doc but getting this error: { "message": "The given data was invalid.", "errors": { "data": [ "The provided credentials are incorrect." ] } } Here’s the controller: public function login(Request $request) { $request->validate([ ’email’ => ‘required’, ‘password’ => ‘required’, ‘device_name’ => ..

Read more