Very strange behavior with save(). I don't use method create. This is the creating new record code:
public function store(Request $request)
{
$this->validate($request,[
'title' => 'required',
'weight' => 'required|integer|max:99,min:-99',
'color' => 'required|http://regex:/^#[0-9A-F]{6}$/',
'suspension' => 'required|integer|in:0,1'
]);
$status = new Status();
$status->weight = $request->weight;
$status->title = request('title');
// dd($request->title);
$status->color = $request->color;
$status->suspension = $request->suspension;
$status->description = $request->description;
$status->save();
$request->session()->flash('status','success');
$request->session()->flash('msg',__('Status has benn created Successfully'));
return redirect('/status');
}
However, I have got the following message about the title field:
SQLSTATE[HY000]: General error: 1364 Field 'title' doesn't have a default value (SQL: insert into
statuses(weight,color,suspension) values (-9, #FFD700, 0))
So it is not an issue of $fillable!
I have the translation package Laravel Translatable. Just when stop using it from Status model, it saves fine!
However I have another model which uses the same package with the same way but it could able to save new records successfully!
I could not able to figure out the root cause f this issue.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire