I’m having trouble passing a variable that stores a certain value to with()
, it returns what I want, but it returns the following message.
[{"name":"Ryu"}] won updates in your informations.
rather then Ryu won updates in your informations.
public function update(FighterRequest $request, $id)
{
$validations = $request->validated();
FighterModel::where('id',$id)->update($validations);
$name_fighter = DB::table('fighters')->select('name')->where('id','=',$id)->get();
return redirect('fighter')->with('success-update',"$name_fighter won updates in your informations.");
}
3
Answers
Your
$name_fighter
returns a collection. So rather than using$name_fighter
directly, you need to specify what you want to get$name_fighter->name
Would try this version because get return multiple objects but first only object