"12" ] Submit from the form, I need 2 and 7, what d...">

How to get the key from a laravel form request?

I have an array

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

Submit from the form, I need 2 and 7, what do I call them?

Keys are identifiers of the parts that want it that way. foreach get 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 someone tell me how to do this?

Thanks in advance.

+9
source share
3 answers

Use the notation $key => $value in foreach :

 foreach ($request->except('_token') as $key => $part) { // $key gives you the key. 2 and 7 in your case. } 
+14
source
 $data = $request->except('_token') foreach($data as $id => $value){ echo "My id is ". $id . " And My value is ". $value; } 
+6
source

If you want to access only one key $request , you can use:

 $request->key_name 

to achieve this goal.

example

I sent the image in the postman like this: Postman image upload example

And I got this in a Laravel controller as follows:

 public function store(SendMessageRequest $request) { $image = $request->image; // this is what You need :) // ... } 
0
source

Source: https://habr.com/ru/post/1260358/


All Articles