samedi 10 février 2018

getting user profile using a slug

I am trying to retrieve a user profile using a unique slug. With the user signed in, I can only get the first profile recorded in the db instead of the signed in user, and I am not sure why? I still wanna be able to see the profiles if I am not signed in.

Route

Route::group(['prefix' => '/profile'], function () {
    Route::get('/{profile}', 'Profile\ProfileController@index')->name('profile.index');

Controller

class ProfileController extends Controller
{
    public function index(Profile $profile)
    {
        return view('overview.profile.index', [
            'profile' => $profile,
        ]);
    }
}

From Blade

<li>
    <a href="">Profile</a>
</li>

Composer

class ProfileComposer
{
    public function compose(View $view)
    {
        if (!Auth::check()) {
            return;
        }

        $view->with('profile', Auth::user()->profile->first());

    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire