Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel存储到数据库_Php_Jquery_Laravel_Laravel 5_Blade - Fatal编程技术网

Php Laravel存储到数据库

Php Laravel存储到数据库,php,jquery,laravel,laravel-5,blade,Php,Jquery,Laravel,Laravel 5,Blade,我的表格中有两个基于第一个选择选项的依亲下拉列表。 当我试图存储到数据库时,我遇到以下问题 Integrity constraint violation: 1048 Column 'service_id' cannot be null 有人能帮我确定我的问题在哪里以及如何解决吗?我认为这与我的存储方法有关,因为依赖项丢失了 以下是我如何传递到视图: $services = \DB::table('services')->lists("name", "id"); return

我的表格中有两个基于第一个选择选项的依亲下拉列表。 当我试图存储到数据库时,我遇到以下问题

Integrity constraint violation: 1048 Column 'service_id' cannot be null 
有人能帮我确定我的问题在哪里以及如何解决吗?我认为这与我的存储方法有关,因为依赖项丢失了

以下是我如何传递到视图:

 $services = \DB::table('services')->lists("name", "id");
    return view ('reservations', compact('services'));
以下是我的表格:

  {!! Form::open(array("url"=>"bookings", "class"=>"form-horizontal")) !!}

                <select name="service" class="form-control" style="width:350px">
                    <option value="">--- Select Service ---</option>
                    @foreach ($services as $key => $value)
                    <option value="{{ $key }}">{{ $value }}</option>
                    @endforeach
                </select>
                <br />
                    <label for="price">This cost for this service is:</label><br />
                    <select name="price">
                        <option id="price"></option>
                    </select><br />
                    <label for="time">This duration for this service is:</label><br />
                    <select name="time">
                        <option id="time"></option>
                    </select>
                    <br />
                    <br />
                    {!! Form::label("booking_date", "Enter Date", array("class"=>"col-md-2")) !!}
                    {!! Form::text("booking_date","",array("placeholder"=>"Enter Date", "class="=>"form-control")) !!}
                    <br />
                    <br />
                    {!! Form::label("booking_time", "Enter Time", array("class"=>"col-md-2")) !!}
                    {!! Form::text("booking_time","",array("placeholder"=>"Enter Time", "class="=>"form-control")) !!}
                    <br />
                    <br />
                    {!! Form::submit('Book', array("class"=>"btn btn-primary","id"=>"btn")) !!}

                 {!! Form::close() !!}
在模型中:

  protected $fillable = ['service_price', 'service_time','booking_date', 'booking_time'];

非常简单,数据库中有一个名为
service\u id
的字段,必须填写该字段并具有值

在php中,您希望表单字段名为
serviceID
,但在html中,您将其称为
service

<select name="service" class="form-control" style="width:350px">


不同的名称,请将其中一个更改为另一个。

超级简单,数据库中有一个名为
service\u id
的字段,必须填写并具有值

在php中,您希望表单字段名为
serviceID
,但在html中,您将其称为
service

<select name="service" class="form-control" style="width:350px">


不同的名称,所以请将其中一个更改为另一个。

您的选择表单字段名“服务”,但您尝试使用$request->get('serviceID')获取值,这就是为什么出现错误的原因。 替换存储方法

public function store(Request $request,int $service)
{
    //
    $data = \Input::only("booking_date", "booking_time");
    $bookings = new Booking($data);
    $bookings->user_id = auth()->user()->id;
    $bookings->service_id = $request->get('service');
    $bookings->service_price = $request->get('price');
    $bookings->booking_date = $request->get('booking_date');
    $bookings->booking_time = $request->get('booking_time');
    $bookings->save();
    return redirect('/');
}
或者将store方法的第四行替换为

  $bookings->service_id = $request->get('service');

您的选择表单字段名为'service',但您试图使用$request->get('serviceID')获取值,这就是您的get错误的原因。 替换存储方法

public function store(Request $request,int $service)
{
    //
    $data = \Input::only("booking_date", "booking_time");
    $bookings = new Booking($data);
    $bookings->user_id = auth()->user()->id;
    $bookings->service_id = $request->get('service');
    $bookings->service_price = $request->get('price');
    $bookings->booking_date = $request->get('booking_date');
    $bookings->booking_time = $request->get('booking_time');
    $bookings->save();
    return redirect('/');
}
或者将store方法的第四行替换为

  $bookings->service_id = $request->get('service');

您没有在表单中传递serviceID。您没有在表单中传递serviceID。我相信您以错误的方式填写了select元素的选项。。检查生成的HTML并将其写在这里。我相信您以错误的方式填写了select元素的选项。。检查生成的HTML并将其写入此处。