the where returns a collection. You need to loop through it to get each profile.
$profiles = Profile::where('slug', '=', $slug)->get();
foreach($profiles as $profile){
echo $profile->name;
}
if the slug is unique you can just get the first item on the collection
echo Profile::where('slug', '=', $slug)->first()->name;
ok, thanks.
i have this in my ProfileController
$profile = Profile::where('slug', '=', $slug)->first()->name;
return view('singleProfile')->with('profile', $profile);
How to output in view ?
{{ $name }}
{{ $profile->name }}
gives me error.
Hi, You are doing it wrong. Your querry returns only name.
Use like this:
$profile = Profile::where('slug', '=', $slug)->first();
return view('singleProfile')->with('profile', $profile);
And then in view:
{{ $profile->YOUR_FIELD }}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community