我收到以下错误:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'matricule_per' cannot be null (SQL: insert into `permissions` (`matricule_per`, `date_rentree`, `nbr_jour`, `nbr_jour_reste`, `updated_at`, `created_at`) values (?, ?, ?, ?, 2020-03-05 19:56:59, 2020-03-05 19:56:59))
这是我的表格:
<div class="form-group row">
<label class="col-form-label col-md-4">Matricule :</label>
<div class="col-md-8">
<select name="matricule_per" class="form-control">
@foreach ($personnes as $p)
<option value="{{$p->id}}">{{$p->mle}}</option>
@endforeach
</select>
</div>
</div>
这是PermissionController:
public function insertPer(Request $request)
{
$perm = new Permission();
$perm->matricule_per = $request->input('matricule_per');
$perm->date_rentree = $request->input('date_rentree');
$perm->nbr_jour = $request->input('nbr_jour');
$perm->nbr_jour_reste = $request->input('nbr_jour_reste');
$perm->save();
return redirect('permission');
}
public function indexP()
{
$personnes = DB::table('personnes')->select('id','mle')->get();
return view('frontend.Permission', compact('personnes'));
}
在模型中像其他一样在$ fillable上添加
protected $fillable = ['matricule_per'];
或只是添加此
protected $guared = [];
有关详细信息,请检查此https://laravel.com/docs/5.7/eloquent#mass-assignment
如果您不想填写此内容,或者有时它可以为null,则应在迁移文件中将其设置为null
$table->string('matricule_per')->nullale();
您应该通过添加新的迁移或相同的迁移来编写它。如果您对先前的迁移进行了更改,则应给出
php artisan migrate:refresh
如果您只是添加新的迁移
php artisan migrate
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句