html - Laravel - 将两个选择值插入数据库

标签 html mysql laravel laravel-5 eloquent

我想将目标输入值插入数据库,但它给了我一个错误,请参阅此处。问题是什么?

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'destination' cannot be null (SQL: insert into aircraft_flights (flight_number, iata_flight_number, flight_date, departure_time, arrival_time, from_location, destination, aircraft_id) values (FK2457, SQ1, 2018-03-02T04:03, 2018-04-04T04:25, 2018-05-06T16:02, Philippines, , 4))

这是我的目的地表单输入

 <div class="col-md-4 col-sm-4 ">
    {{Form::label('from_location', 'From')}} 
    {{Form::select('from_location', trans('countries'),null,['class' => 'form-control', 'placeholder' => 'Select where you From'])}}<br>
</div>
<br>

<div class="col-md-4 col-sm-4 ">
    {{Form::label('destination', 'Destination Country')}} 
    {{Form::select('destination', trans('countries'),null,['class' => 'form-control', 'placeholder' => 'Select where is your Destination'])}}<br>
</div>
<br>

我的迁移

 $table->increments('id');
        $table->string('flight_number');
        $table->string('iata_flight_number');
        $table->dateTime('flight_date');
        $table->dateTime('departure_time');
        $table->dateTime('arrival_time');
        $table->string('from_location');
        $table->string('destination');
        $table->integer('aircraft_id');

我的 Controller

 $aircraftFlight = new AircraftFlights;
    $aircraftFlight->flight_number = $request->input('flight_number');
    $aircraftFlight->iata_flight_number = $request->input('iata_flight_number');
    $aircraftFlight->flight_date     = $request->input('flight_date');
    $aircraftFlight->departure_time = $request->input('departure_time');
    $aircraftFlight->arrival_time = $request->input('arrival_time');
    $aircraftFlight->from_location = $request->input('from_location');
    $aircraftFlight->destination     = $request->input('destination ');
    $aircraftFlight->aircraft_id = $request->input('aircraft_id');

    $aircraftFlight->save();

    return redirect('/admin/aircraftflights')->with('success', 'Flight Created');

我的模特

protected $table = 'aircraft_flights';
// Primary Key
public $primaryKey = 'id';
// Timestamps
public $timestamps = false;

最佳答案

我读到的内容中您缺少目的地输入。在您的示例中,from_locationPhilippines,并且 destination 为 NULL,则 heaven_id 为 4

当您将其添加到您的模型时,它应该可以解决问题(然后可以传递NULL)

protected static $strictMode = false;

关于html - Laravel - 将两个选择值插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53594496/

相关文章:

javascript - 我怎样才能让我的鼠标看起来像一个指针图标?

html - 如何去掉 slider 左右两侧不需要的空白区域?

mysql - 将全文搜索的分数相加 MATCH 在一起

php - Ajax 返回格式化整数

php - 使用 whereHas 方法的 Laravel Eloquent 查询的奇怪行为

javascript - 使用 Goutte/Guzzle 设置用户代理 header ? (未定义的方法错误)

Laravel Controller 子文件夹路由

html - 如果前一个元素中有元素,则隐藏文本

javascript - 定位 z-index 没有按预期工作

javascript - 类型错误 : Attempted to wrap undefined property query as function