Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i loop through request()-> all() post (Laravel) data?

I am trying to loop through the request:: all() array and return the values, but instead, am getting just the token.

This is what i am currently trying, but its returning just the form token

This is the JSON 

1   "microwaves"
2   "has enough energy to remove electrons from atoms"
3   "thyroid"
4   "stop immediately when switch is turned off"
5   "travel in a straight line"
6   "xrays and electrons"
7   "the radiation that hits the imaging plate"
8   "American limits and radiation allowances"
9   "genetic effects, those passed room parent to child"
10  "maximize distance from the source"
_token  "ABB88ZTnMAQ9DkuHb546aubz9ufK2SZQWxaKgm7w"
public function store(){
  $data = request()->all();

  foreach ($data as $key) {
    return $key;
  }
``

like image 282
Vanye Wadawasina Avatar asked Oct 16 '25 08:10

Vanye Wadawasina


1 Answers

You forgot to put Request $request in the store parameters:

public function store(Request $request) {    
    $data = $request->all();

    foreach ($data as $key => $value) {
        return $value;
    }
}


And if you are trying to get the whole request, except the _token, then use this:
public function store(Request $request) {    
    $data = $request->except('_token');

    foreach ($data as $key => $value) {
        return $value;
    }
}
like image 63
chunterb Avatar answered Oct 19 '25 01:10

chunterb