Migration
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();
});
Here start_date set as column type date and nullable
When running Insert function like below its inserting null values
$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);
When Updating the same row left blank as end_date input,
$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);
How can I make it NULL like insert function in update? My strict mode is false now, If I make it true it will throw an exception of invalid data for the end_date column.