简体   繁体   English

SQLSTATE [22007]:无效的日期时间格式:1366 不正确的 integer 值:问题

[英]SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: problem

    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]: Invalid datetime format: 1366 Incorrect integer value: 'active' for column kintshop . SQLSTATE [22007]:无效的日期时间格式:1366 不正确的 integer 值:列kintshop的“活动”。 categories . categories parent_id at row 1 (SQL: insert into categories ( title , summary , is_parent , parent_id , photo , status , slug , updated_at , created_at ) values (dsadasd,第 1 行的parent_id (SQL:插入categoriestitlesummaryis_parentparent_idphotostatusslugupdated_atcreated_at )值(dsadasd、

dsadasdas沙达斯达斯

, 1, active, /storage/photos/1/category1.png, active, dsadasd, 2021-06-04 13:09:04, 2021-06-04 13:09:04)) , 1, 活动, /storage/photos/1/category1.png, 活动, dsadasd, 2021-06-04 13:09:04, 2021-06-04 13:09:04))

Here is my schema这是我的架构

 **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(); });**

Error is clear.错误很清楚。 Request contain parent_id value active but migration file says parent_id is foreign key you must pass accurate value to create method. Request包含activeparent_id值,但migration文件说parent_idforeign key ,您必须传递准确的值才能创建方法。

parent_id data type is Big Integer parent_id数据类型为Big Integer

See your $request->all() data查看您的$request->all()数据

 [▼ "_token" => "LrDekkz85cys4ZFx4vCFmy0VPHwFCh1u7aPIcEqq"

 "title" => "dsadasd" 
 "summary" => "<p>dsadasdas</p>" 
 "files" => null
 "is_parent" => "1" 
 "parent_id" => "active" 
 "photo" => "/storage/photos/1/category1.png"
 "status" => "active" ]

So better update validation rule for parent_id contain only integer所以更好地更新parent_id的验证规则只包含 integer

Table column 'parent_id' is bigInteger but you have 'active' (string) in your request, so, change data type on DB or update validation rules.表列“parent_id”是 bigInteger,但您的请求中有“活动”(字符串),因此,更改数据库上的数据类型或更新验证规则。

TIP: don't use '$request->all()', is not safe.. you can use instead '$request->only('title', 'summary', 'status'.....)'.提示:不要使用 '$request->all()',不安全.. 你可以使用 '$request->only('title', 'summary', 'status'.....)' . This is a safe practice to retrieve params from request这是从请求中检索参数的安全做法

$this->validate($request,[
        'title' => 'string|required',
        'summary' => 'string|nullable',
        'is_parent' => 'sometimes|in:1',
        'parent_id' => 'nullable',
        'status' => 'nullable|in:active,inactive'
]);

This is wrong...$this->validate([]) accept the rules first as argument, not the request.这是错误的...... $this->validate([]) 首先接受规则作为参数,而不是请求。 Maybe you must do也许你必须做

$request->validate([
        'title' => 'string|required',
        'summary' => 'string|nullable',
        'is_parent' => 'sometimes|in:1',
        'parent_id' => 'nullable',
        'status' => 'nullable|in:active,inactive'
]);

or或者

$validation = Validator::make($request->all(),[rules]);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQLSTATE [22007]:无效的日期时间格式:1366不正确的整数值 - SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value Laravel 8:SQLSTATE[22007]:无效的日期时间格式:1366 不正确的 integer 值 - Laravel 8: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value SQLSTATE [22007]:无效的日期时间格式:1366错误的整数值:行1的列&#39;infraction_id&#39;的&#39;[“ 1”,“ 3”,“ 66”,“ 68”]&#39; - SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '[“1”,“3”,“66”,“68”]' for column 'infraction_id' at row 1 SQLSTATE[22007]:无效的日期时间格式:1366 不正确的整数值:Laravel 中的“column_name” - SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'column_name' in Laravel SQLSTATE [22007]:无效的日期时间格式:1366 不正确的 integer 值:“isVisible”列的“true” - SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'true' for column 'isVisible' QLSTATE [22007]:无效的日期时间格式:1366 不正确的 integer 值 laravel - QLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value laravel SQLSTATE[22007]:无效的日期时间格式:1366 字符串值不正确,html_entity_decode function - SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value, html_entity_decode function laravel SQLSTATE [22007]:无效的日期时间格式:1366不正确的十进制值:&#39;buy_amt * 0.00097812555575316&#39;为行1上的价格列错误 - laravel SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect decimal value: 'buy_amt * 0.00097812555575316' for column 'price' at row 1 error SQLSTATE[22007]:无效的日期时间格式:1292 日期时间值不正确 - SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value 无效的日期时间格式:1366不正确的整数值: - Invalid datetime format: 1366 Incorrect integer value:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM