I Am getting this error
(Undefined property: stdClass::$Blanch)
While trying to call the relation data in blade {{$req->Blanch->name}}
I have created the function in model
public function Blanch()
{
return $this->belongsTo(Blanch::class, 'branch_id', 'id');
}
I dont know what is missing anyone with idea can help
$req= DB::table('fuel_requests')
->LeftJoin('pumps','fuel_requests.pump_id','=','pumps.id')
->LeftJoin('cars','fuel_requests.car_id','=','cars.id')
->select('fuel_requests.*')
->get();
while in my model i have
protected $table = "fuel_requests";
protected $fillable = ['type', 'branch_id', 'car_id', 'pump_id','quantity', 'user_id', 'name', 'deadline', 'verified_by', 'approved_by', 'supplied_by', 'received_by', 'status'];
The error you are getting for undefined property because you are not loading eloquent relation Blanch
, try using with()
on FuelRequest
model
$req = FuelRequest::with('Blanch')->get();
Not sure why you are using left joins when you are not selecting any columns from these table nor applying any filter or aggregation.
Este artigo é coletado da Internet.
Se houver alguma infração, entre em [email protected] Delete.
deixe-me dizer algumas palavras