Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get id from url with Request $request? (Laravel 5.3)

My link href on the view is like this :

<a href="{{ route('message.inbox.detail.id', ['id' => $message->id]) }}" class="btn btn-default">
    <span class="fa fa-eye"></span> {{ trans('button.view') }}
</a>

My routes is like this :

Route::get('message/inbox/detail/id/{id}', ['as'=>'message.inbox.detail.id','uses'=>'MessageController@detail']);

When clicked, the url display like this :

http://myshop.dev/message/inbox/detail/id/58cadfba607a1d2ac4000254

I want get id with Request $request

On the controller, I try like this :

public function detail(Request $request)
{
    dd($request->input('id'));
}

The result : null

How can I solve it?

like image 435
samuel toh Avatar asked Mar 17 '17 02:03

samuel toh


People also ask

What is request -> input () in laravel?

input() is a method of the Laravel Request class that is extending Symfony Request class, and it supports dot notation to access nested data (like $name = $request->input('products.0.name') ).

How can pass query string in URL in laravel?

You can pass query string to URL in laravel using named route and controller action. You can pass query string as comma separated array to named route and controller action and redirect to URL.

How do I get params in laravel?

Method 1: $request->route('parameter_name') We can access route parameters in two ways. One way is by using $request->route('parameter_name') ., where parameter_name refers to what we called the parameter in the route.


1 Answers

You can get it like this

$request->route('id')

Inside request class you can access it this way

$this->route('id')

I usually use it when I'm validating field to make sure it's unique, and I need to exclude model by ID when I'm doing update

like image 197
Martynas A. Avatar answered Sep 28 '22 04:09

Martynas A.