你好,我的路由如下
Route::get('/patients','PatientController@index');
Route::get('/patients/create','PatientController@create');
Route::post('/patients/store','PatientController@store');
在create.blade.php代码如下,
{!! Form::open(['action'=>'PatientController@store','method'=>'post']) !!}
<div class="form-group">
{!! Form::label('name','Name:') !!}
{!! Form::text('name',null,['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('gender','Gender:') !!}<br>
Male: {!! Form::radio('gender','1',['class'=>'form-control','checked'=>'']) !!}<br>
Female: {!! Form::radio('gender','0',['class'=>'form-control','checked'=>'']) !!}
</div>
<div class="form-group">
{!! Form::label('phone','Phone:') !!}
{!! Form::text('phone',null,['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('email','Email:') !!}
{!! Form::text('email',null,['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('age','Age:') !!}
{!! Form::text('age',null,['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('surgeon','Surgeon:') !!}
{!! Form::text('surgeon',null,['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit('Add Patient',['class'=>'btn btn-success form-control']) !!}
</div>
{!! Form::close() !!}
在提交这个表单的时候无法使用Request获取数据,获取的数据是空array
class PatientController extends Controller
{
public function index()
{
$patients = Patient::latest()->get();
return view('patients/index',compact('patients'));
}
public function show($id)
{
$patient = Patient::findOrFail($id);
return view('patients/show',compact('patient'));
}
public function create()
{
return view('patients/create');
}
public function store()
{
$request = new Request;
$input = $request->all();
print_r($input);
print_r($request->url());
print_r($request->method());
return $request->getContent();
}
结果如下
Array ( ) http://:GET_token=yA68V9qgYCW6xPwCViWdwx3jXx2Bpn0sz9gW7pjW&name=p2&gender=0&phone=6476436543&email=p2%40test.com&age=22&surgeon=1
非常困惑,谢谢啦