Support the ongoing development of Laravel.io →
Database Eloquent Blade
Last updated 2 years ago.
0

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;
Last updated 9 years ago.
0

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.

Last updated 9 years ago.
0

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 }}
0

Sign in to participate in this thread!

Eventy

Your banner here too?

muellernm muellernm Joined 15 Apr 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.