Are you setting $leaveEntitlements anywhere else? It seems you are loading multiple some place (->get()) and trying to get user on that.
Sep 11, 2020
11
Level 1
Property does not exist on this collection instance.
I'm having a bit of a problem with calling the values from the table of a user when im trying to edit that user through another table and im getting the error that the property does not exist I tried to add the belongsTo on the model but its still not working
Heres the controller
public function edit($id)
{
$teams =Team::all();
$departments =Department::all();
$leaveEntitlements=LeaveEntitlement::find($id);
return view('manageleave.index', compact('departments','leaveEntitlements','user'));
}
public function update(Request $request, $id)
{
$leaveEntitlements = LeaveEntitlement::find($id);
$leaveEntitlements->update($request->all());
return redirect()->route('manageleave.index')->with('message', 'LeaveEntitlement updated');
}
And heres the model
public function user(){
return $this->belongsTo(User::class,'user_id','id');
}
And im using it here but i want to add more to it inside the forms like other columns data but it catches an error here first
<form method="POST" action="{{route('manageleaves.update',[$leaveEntitlements->user->id])}}">
The error is this
Property [user] does not exist on this collection instance.
Level 1
Okay so i figured it out , changed the relation for it
public function entitlement(){
return $this->hasOne(LeaveEntitlement::class,'user_id','id');
}
And its working now
Please or to participate in this conversation.