我正在尝试通过 POST 从我的表单中存储数据,但它没有达到我的存储操作,我尝试了几种方法,但都没有对我有用。
ContactController 中的存储方法:
public function store(StoreMessage $request)
{
Log::info('Storing message: '.$request);
Message::create([
'name' => $request->name,
'email' => $request->email,
'phonenumber' => $request->phonenumber,
'text' => $request->text
]);
}
看法:
{!! Form::open(['action' => 'ContactController@store']) !!}
{!! Form::label('name', 'Name') !!}
{!! Form::text('name', null, ['class' => 'form-control', 'required']) !!}
{!! Form::submit('Creëer de activiteit!', array('class' => 'btn btn-primary', 'id' => 'createSubmit')) !!}
{!! Form::close() !!}
路线:
Route::get('/contact', 'ContactController@index');
Route::post('/contact', 'ContactController@store');
这是 StoreMessage 请求:
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreMessage extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required',
'email' => 'required',
'text' => 'required',
];
}
}