며칠 전 나는 larvel을 laracast에서 배우기 시작했고 작은 문제가 있습니다.Laravel null 컨트롤러의 POST 데이터
게시 방법을 사용하여 양식 데이터를 제출하고 컨트롤러에서이 데이터에 액세스하려는 경우 값이 비어 있습니다.
형태 :
<form method="POST" action="{{ url('/costs')}}">
{{ csrf_field() }}
<div class="form-group">
<label for="cost-title">Cost title</label>
<input type="text" class="form-control" id="cost-title" name="title" placeholder="Enter cost title">
</div>
<div class="form-group">
<label for="cost-price">Price</label>
<input type="text" class="form-control" id="cost-price" name="price" placeholder="Enter price">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
컨트롤러 : 나는 덤프 죽을 때
Route::get('/costs', '[email protected]');
Route::get('/cost/{cost}', '[email protected]');
Route::get('/costs/create', '[email protected]');
Route::post('/costs', '[email protected]');
그리고 :
<?php
namespace App\Http\Controllers;
use App\Cost;
class CostsController extends Controller
{
public function index(){
$costs = Cost::all();
return view('costs.index', compact('costs'));
}
public function show(Cost $cost){
return view('costs.show', compact('cost'));
}
public function create(Cost $cost){
return view('costs.create');
}
public function store(){
dd(request()->all);
}
}
내 노선에서 나는 포스트 방법을 사용하여 @store 트리거하고 있습니다 요청 :
public function store(){
dd(request()->all);
}
값이 null입니다. 왜 내가 여기에 어떤 데이터도 볼 수없는 이유를 설명해 주시겠습니까?
{public function store (Request $ request) { dd ($ request-> all()); }' – Maraboc
@Maraboc, 시도했지만 다음과 같은 오류가 있습니다 : "App \ Http \ Controllers \ Request 클래스가 존재하지 않습니다." – VividDreams
컨트롤러 상단에 'Use Illuminate \ Http \ Request;'를 추가하십시오;) – Maraboc