Right way to build a link in laravel 5.3

前端 未结 4 704
逝去的感伤
逝去的感伤 2021-01-03 09:29

Im trying to build a dynamic link with a view page (blade) with Laravel 5.3.

My approach is:



        
4条回答
  •  走了就别回头了
    2021-01-03 10:12

    You can use named routes for cleaner in code

    In your app/Http/routes.php (In case of laravel 5, laravel 5.1, laravel 5.2) or app/routes/web.php (In case of laravel 5.3)

    Define route

    Route::get('articles/{id}/edit',[
                 'as'   =>'articles.edit',
                 'uses' =>'YourController@yourMethod'
                ]);
    

    In Your view page (blade) use

    Edit
    

    One benefits of using named routes is if you change the url of route in future then you don't need to change the href in view (in your case)

提交回复
热议问题