sumeshvasu
3 months ago
855
13
Laravel

Field missing in ::create but works with ::insert

Posted 3 months ago by sumeshvasu

field missing - vehicle_brand & vehicle_model

while running Model::create. The table has those fields. I have created one array before this statement. then I printed that array. Corresponding all field elements are listed.

//Repository file code

$vehicle = [
  'user_id' => $user->id,
  'vehicle_type' => $request['vehicle_type'],
  'vehicle_brand' => 'brand',
  'vehicle_model' => 'model',
  'vehicle_color' => $request['vehicle_color'],
   'vehicle_number' => $request['vehicle_number'],
  'status' => true,
 ];

//dd($vehicle);
$this->freelancerVehicleModel::create($vehicle);

//model code

protected $fillable = [
        'user_id', 
        'vehicle_type', 
        'vehicle_brand ', 
        'vehicle_model ', 
        'vehicle_color', 
        'vehicle_number', 
        'status',
];

//below error getting in postman

General error: 1364 Field 'vehicle_brand' doesn't have a default value (SQL: insert into freelancer_vehicles (user_id, vehicle_type, vehicle_color, vehicle_number, status, updated_at, created_at) values (1795bf65-d4f9-4604-bd81-83f3c1fc3623, bike, red, KL368B 6769, 1, 2020-07-18 19:27:41, 2020-07-18 19:27:41)) in file /home/vagrant/code/askalan/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 669

Please help me to solve this issue.

Please sign in or create an account to participate in this conversation.