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.
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.
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') ).
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.
Use Collection
for a one-lined code instead of foreach()
.
$requestKeys = collect($request->all())->keys();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With