Unexpected data found. Unexpected data found. Data missing

2018-01-17 23:36:26

错误代码

public function write($category,Request $request)
{
   $title = UsedCarCategory::find($category)->name;
   $id = $request->input('id');

   $article = "";
   if($id==""){
       /*添加文章*/
   }else{

       $article = UsedCar::find($id);
   }

   return view('/usedCar/write',["article"=>$article,"title"=>$title,"category"=>$category]);
}

上面的代码,再正常不过了,不知道为啥出现了下面的错误

InvalidArgumentException
Unexpected data found. Unexpected data found. Data missing


从网上查出


up vote1down voteaccepted

You're passing null as a string instead of the datatype. Remove the quotes, and it will work:

$date = Carbon::createFromDate(null, rand(1,12), rand(1,28));
// object(Carbon\Carbon)(
//   'date' => '2017-06-02 10:28:17.000000',
//   'timezone_type' => 3,
//   'timezone' => 'America/New_York'
// )

Your next error, you're missing a second colon after DB:

DB::table('utilisateurs')->insert


我仔细检查我没有这个错误。


后来去数据库看,并不是我的错误,代码并没有错误。


created_at   我竟然设置成了time字段。

然后就报错了,不能查询出时间的原因,应该是timestamp才对。


哎 ,这错误。

  • 2020-02-19 23:04:52

    理解Laravel中的pipeline

    pipeline在laravel的启动过程中出现次数很多,要了解laravel的启动过程和生命周期,理解pipeline就是其中的一个关键点。网上对pipeline的讲解很少,所以我自己写一写吧。

  • 2020-02-19 23:08:56

    Laravel 用户认证 Auth(精华)

    很多应用是需要登陆后才能操作,Laravel 提供了一个 auth 工具来实现用户的认证功能。并且有一个 config/auth.php 来配置 auth 工具。大概看一下 auth 工具的常用方法

  • 2020-02-19 23:12:44

    Laravel 从 $request 到 $response 的过程解析二(必读)

    laravel 的请求会组装成 $request 对象,然后会依次经过中间件(前置部分),最终到达 url 指向的控制器方法,然后把返回数据组装为 $response 对象返回,再依次经过中间件 (后置部分),最终返回。