lundi 11 mars 2019

URL is not getting username from route in Laravel 5

I am trying to show author page by the URL: domian.com/author/page/{username}.

Here is the route: Route::get('author/page/{username}', 'FrontendAuthorController@index');

Here is the controller (FrontendAuthorController@index):

public function index($username)
{
    $user = BasicInfo::where('username', $username)->first(); //'username' is a field of BasicInfo Model. 
                                                              //BasicInfo belongs to User model. 
                                                              //So, we can get user id by $user->user_id according to eloquent rule. 

    $author = User::findOrFail($user->user_id);


    return view('frontend.author', compact('author'));
}

But I get this message in view

"Sorry, the page you are looking for could not be found."

If I try to get view with this route domian.com/author/page/{username}/{id} with this parameter function index($username, $id) then I get the view! I don't want to show id in route/url. how can I solve this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire