Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the key from a laravel form request?

I have an array

array:2 [▼
  2 => "12"
  7 => "12"
]

Send from a form, I need the 2 and 7 how do i call them?

The keys are id's of parts so want to. foreach get the ID and value then update something...

foreach($request->except('_token') as $part) {
    /*get Key here (in this case 2 or 7) and get value here (in this case both 12)*/
}

Can somebody tell me how to do this?

Thanks in advance.

like image 361
Rubberduck1337106092 Avatar asked Nov 25 '16 14:11

Rubberduck1337106092


People also ask

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.

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 you retrieve the full URL for the incoming request Laravel?

The “path” method is used to retrieve the requested URI. The is method is used to retrieve the requested URI which matches the particular pattern specified in the argument of the method. To get the full URL, we can use the url method.


1 Answers

Use Collection for a one-lined code instead of foreach().

$requestKeys = collect($request->all())->keys();
like image 114
Dani Fadli Avatar answered Oct 29 '22 17:10

Dani Fadli