Миграция
Schema::create('users', function (Blueprint $table) {
$table->increments('user_id');
$table->string('username',50)->unique();
$table->date('start_date');
$table->date('end_date')->nullable();
$table->timestamps();
});
Здесь start_date задается как дата типа столбца и может иметь значение NULL
При запуске функции вставки, как показано ниже ее вставки нулевых значений
$insert = [
'username' =>strtoupper(request('username')),
'password' =>Hash::make(request('password')),
'start_date' =>date('Y-m-d',strtotime(request('start_date'))),
];
if(request()->filled('end_date')){
$insert['end_date'] = date('Y-m-d',strtotime(request('end_date')));
}
User::create($insert);
![enter image description here](https://i.stack.imgur.com/ghXl6.png)
При обновлении той же строки, оставленной незаполненной как ввод end_date,
$user = User::GetWithEncrypted(request('user_id'));
$update ['start_date'] = date('Y-m-d',strtotime(request('start_date')));
if(request()->filled('end_date')){
$update['end_date'] = date('Y-m-d',strtotime(request('end_date')));
}else{
$update['end_date'] = 'NULL';
}
$user->update($update);
В таблице это выглядит как ниже ![enter image description here](https://i.stack.imgur.com/qyEHA.png)
Как я могу сделать его пустым как функция вставки в обновлении?Мой строгий режим теперь ложен. Если я сделаю это, он выдаст исключение недопустимых данных для столбца end_date.