skip to Main Content

Laravel where condition within 'with'

I have an eloquent query: $cameras=Jump::Video() ->with('flight','flight.aircraft','flight.airfield') ->with('student','student.logininfo','student.logininfo.reservations') ->with('camera','camera.status') ->whereBetween('data',[ $from, $to]) ->orderBy($sortBy, $orderDesc) ->paginate($request->perPage); and relations between student, logininfo and reservations Model Jump.php public function scopeVideo($query) { return $query->where('exercise', '104'); } public function student() { return $this->hasOne('AppModelsPersonalData','id','student'); } Model…

VIEW QUESTION

Laravel successfully adding item in one to many relationship model but it is not being added to database

please help, I've been stuck here since then. I want to insert shipmentrequestitem from shipmentrequest model using update method public function update(UpdateShipmentRequestRequest $request, $id) { $shipmentRequest = ShipmentRequest::with( 'shipmentRequestItems', )->where('id',$id)->first(); $shipmentRequest->update($request->all()); $validatedData = $request->validated(); $shipmentRequestItems = $validatedData['shipmentRequestItems']; // $shipmentRequest =…

VIEW QUESTION

Laravel When Condition on a column

I have a ModelA with columns: name, last_name, email I want ModelA with the name Test to add an extra where on email what I tried is the following $model_a_res = A::when( function($query){ return $query->where('name','Test'); }, function ($query) { $query->where('email',…

VIEW QUESTION
Back To Top
Search