【发布时间】:2021-08-22 13:09:24
【问题描述】:
public function store(Request $request)
{
$this->validate($request,[
'title' => 'string|required',
'summary' => 'string|nullable',
'is_parent' => 'sometimes|in:1',
'parent_id' => 'nullable',
'status' => 'nullable|in:active,inactive'
]);
$data=$request->all();
$slug=Str::slug($request->title);
$count=Category::where('slug',$slug)->count();
if($count>0){
$slug=$slug.'-'.date('ymdis').'-'.rand(0,999);
}
$data['slug']=$slug;
// return $slug;
$status=Category::create($data);
if($status){
request()->session()->flash('success','Kategori başarıyla eklendi');
}
else{
request()->session()->flash('error','Kategori eklenirken hata oluştu');
}
return redirect()->route('category.index');
}
SQLSTATE[22007]:无效的日期时间格式:1366 不正确的整数值:列 dsadasdaskintshop.categories.parent_id 在第 1 行的“活动”(SQL:插入到 categories (@987654326 @, summary, is_parent, parent_id, photo, status, slug, updated_at, created_at) 值 (dsadasd,
这是我的架构
**Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('slug')->unique();
$table->string('photo')->nullable();
$table->boolean('is_parent')->default(true);
$table->unsignedBigInteger('parent_id')->nullable();
$table->enum('status',['active','inactive'])->default('active');
$table->foreign('parent_id')->references('id')->on('categories')->onDelete('SET NULL');
$table->mediumText('summary')->nullable();
$table->timestamps();
});**
【问题讨论】:
-
dd($data) 并显示您得到的结果并发布迁移文件或表结构