[請益] laravel request->all()

看板PHP作者 (rob)時間6年前 (2018/03/17 12:05), 6年前編輯推噓1(101)
留言2則, 1人參與, 6年前最新討論串1/1
解決了但想請問為何? 用 $search_all['name'] 就可在view中讀到 不過想請問的是 為何範例都是 request->all() 然後$search_all->name 為何網上的介紹是這樣寫的? Retrieving Input Via Dynamic Properties You may also access user input using dynamic properties on the Illuminate\Http\Request instance. For example, if one of your application's forms contains a name field, you may access the value of the field like so: $name = $request->name; When using dynamic properties, Laravel will first look for the parameter's value in the request payload. If it is not present, Laravel will search for the field in the route parameters. ----------------------------------------------- 由上頁的form經由post指定到下面的 controller public function index(Request $request) { $search_all= $request->all(); $search_name = $search_all->name; //error place return $search_all.$search_name; } 或我直接在view <p>{{$search_all->name}}</p> 也會出現錯誤 Trying to get property of non-object 請問要怎樣 將request->all()裡面的數列取出呢? 我知道用request->input('name')可以 但是我不想要一個各取 想要一次在controller取全部 return view('pro.index') ->with('search',$searchall); 這樣送去view然後 在view中 去一個個取出來 {{$search->name}} 不要在controller中取 看文章都是 輕易的在view $search->name 就可以取到 先前送過來form裡面的input select中的name 為何不成功呢? 請教怎麼處理? 解決了 用 $search_all['name'] 就可在view中讀到 不過想請問的是 為何範例都是 request->all() 然後$search_all->name 為何網上的介紹是這樣寫的? Retrieving Input Via Dynamic Properties You may also access user input using dynamic properties on the Illuminate\Http\Request instance. For example, if one of your application's forms contains a name field, you may access the value of the field like so: $name = $request->name; When using dynamic properties, Laravel will first look for the parameter's value in the request payload. If it is not present, Laravel will search for the field in the route parameters. -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 122.116.4.129 ※ 文章網址: https://www.ptt.cc/bbs/PHP/M.1521259529.A.50A.html ※ 編輯: robinnpca (122.116.4.129), 03/17/2018 13:05:23 ※ 編輯: robinnpca (122.116.4.129), 03/17/2018 13:05:47 ※ 編輯: robinnpca (122.116.4.129), 03/17/2018 13:11:48

03/17 13:54, 6年前 , 1F
你去看request all回傳的就知道了
03/17 13:54, 1F

03/17 13:54, 6年前 , 2F
他回傳的是array而非obj
03/17 13:54, 2F
文章代碼(AID): #1Qh9G9KA (PHP)