如何遍历request()-> all()发布(Laravel)数据?

时间:2019-05-10 19:04:37

标签: laravel eloquent

我试图遍历request :: all()数组并返回值,但实际上是获取令牌。

这是我目前正在尝试的方法,但它只返回表单令牌

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;
  }
``

1 个答案:

答案 0 :(得分:0)

您忘记将Request $request放入商店参数:

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

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


而且,如果您尝试获取除_token之外的整个请求,请使用以下命令:

public function store(Request $request) {    
    $data = $request->except('_token');

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