我尝试使用发布请求将数据发布到数据库。我还使用上一页中输入的数据。
I.e
我注意到URL是/ prebook与/ booking / create相对(这是由于个人资料页面将数据传递到控制器并输出。
有什么想法吗?
配置文件控制器
public function prebook() {
$date = Input::get('query', '01/01/2010');
$guests = Input::get('guests', '2');
$restaurant = Input::get('restaurantID', '2');
$restaurantName = Input::get('restaurantName', '2');
$time = Input::get('timeFrom', '2');
return view('userbookings.create')->with('date', $date)
->with('guests', $guests)
->with('restaurant', $restaurant)
->with('restaurantName', $restaurantName)
->with('time', $time);
}
发布表单代码
{!! Form::open(array('route' => 'user.bookings.store','method'=>'POST')) !!}
@include('userbookings.form')
{!! Form::close() !!}
创建表单(示例输入字段)
<div class="row">
<div class="col-md-3">
<p>Party Size:</p>
</div>
<div class="col-md-9">
<div class="form-group">
<input required type="number" class="form-control" value="{{$guests}}" id='partySize' name='PartySize'>
</div>
</div>
</div>
在控制器中存储方法
public function store(Request $request)
{
request()->validate([
'date' => 'required',
'timeFrom' => 'required',
'timeTo' => 'required',
'partySize' => 'required',
'status' => 'required',
'comments' => 'required',
]);
Booking::create($request->all());
return redirect()->route('user.bookings.index')
->with('success','Booking created successfully');
}
迁移代码:
Schema::create('bookings', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
**$table->string('date');**
**$table->string('timeFrom');**
$table->string('timeTo');
**$table->string('partySize');**
$table->string('status');
$table->text('comments');
**$table->text('businessID');**
$table->timestamps();
});