SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'patente' cannot be null (SQL: insert into
cars
(patente
,marca
,modelo
,color
,fecha_ingreso
,updated_at
,created_at
) values (?, ?, ?, ?, ?, 2019-06-10 16:27:35, 2019-06-10 16:27:35)
Route::match(['get', 'post'], '/crear',[
'uses'=>'CarController@crear',
'as'=>'cars.crear'
]);
Short code to form
<div class="row">
<div class="col-md-6"></div>
<form action="{{route('cars.crear')}}" method="post">
@csrf
<div class="row form-group">
<div class="col-md-12">
<label for="true">Patente:</label>
<input type="text" name="patente" size="6" maxlength="6" class="form-control" required>
</div>
</div>
code create and show
public function crear(Request $request){
$patente=$request['patente'];
$marca=$request['marca'];
$modelo=$request['modelo'];
$color=$request['color'];
$fecha_ingreso=$request['fecha_ingreso'];
$car=new Car();
$car->patente=$patente;
$car->marca=$marca;
$car->modelo=$modelo;
$car->color=$color;
$car->fecha_ingreso=$fecha_ingreso;
$car->save();
return redirect()->back();
}
public function show(){
$cars=Car::all();
return view ('lista',['cars'=>$cars]);
}