我正在尝试通过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',
];
}
}
答案 0 :(得分:0)
您可以尝试这样的正常请求Request $request
,并检查它是否正常工作。
您也可以使用$request
验证,如下面的代码。
public function store(Request $request)
{
$rules = [
'name' => 'required',
'email' => 'required',
'text' => 'required',
];
$this->validate($request,$rules);
Log::info('Storing message: '.$request);
Message::create([
'name' => $request->name,
'email' => $request->email,
'phonenumber' => $request->phonenumber,
'text' => $request->text
]);
}