Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel get url on string

can you help me?

if in laravel we want to get a variable in url so in route we must wrote like this:

Route::get('myweb/article/{article_id}','Controller/ArticleController@show');

it will generate like this

www.myweb.com/article/1

and in controller we can get ID with this:

public static function show(){
   list($article_id) = func_get_args();
}

how about if i want url like this:

www.myweb.com/article-1   // assume 1 is article_id

how i must write line in routes.php? and how to get the ID in controller?

like image 681
Donny Akhmad Septa Utama Avatar asked Oct 19 '22 12:10

Donny Akhmad Septa Utama


1 Answers

Did you try something like this:

Route::get('myweb/article-{article_id}','Controller/ArticleController@show');
like image 128
Alexey Mezenin Avatar answered Oct 27 '22 09:10

Alexey Mezenin