How to make dynamic url with multiple vars like in Laravel?

47
March 14, 2019, at 11:00 PM

How to make dynamic url with multiple vars like in Laravel in my own small MVC? Like when I write Route::get('/post/$1/$2', 'PostsController@showUserPosts'). How do you approach this?

Answer 1

Define a route with parameters:

Route::get('posts/{post_id}/{user_id}', 'PostsController@showUserPosts')->name('user-posts');

And in view:

<a href="{{ route('user-posts', ['user_id'=> 1, 'post_id' => 1]) }}">link</a>

For more info check https://laravel.com/docs/5.8/routing#route-parameters

READ ALSO
Yii2 - cannot add foreign key constraint

Yii2 - cannot add foreign key constraint

I am coming from the Laravel worldI know that foreign keys are necessary for relations to work correctly

23
PHP command in Bash does not execute code

PHP command in Bash does not execute code

Ok, so I have a problem with this thing I found on a MacBook AirIt's called terminal and you can do crazy stuff on it

57
Empty Post Data

Empty Post Data

So I'm working on a PHP projectToday wanted to start working on it again

24
why i am getting SMTP connect failed error in PHPMailer?

why i am getting SMTP connect failed error in PHPMailer?

I really don't know what's wrong in my codeI am creating contact us form by which user can send email to me

27