使用find时,Laravel find返回2行

时间:2017-03-20 11:38:56

标签: laravel-5

我有以下选择我的类别:

dd(Categories::find($id)->get();
dd($category);

但它正在选择2行

enter image description here

当我使用

dd(Categories::where('id',$id)->get());
dd($category);

它起作用并返回

enter image description here

我的桌子结构

    Schema::create('categories', function (Blueprint $table) {
        $table->increments('id');
        $table->string('category');
        $table->integer('parent')->nullable();
        $table->softDeletes();
        $table->timestamps();
    });

    DB::statement("ALTER TABLE categories ADD image LONGBLOB");

1 个答案:

答案 0 :(得分:0)

  

通常find()通过其主键提取单个模型。回报   value是单个模型,集合或null

     

get()提取您已构建的查询

你搞砸了并找到了

Categories::find($id)

Categories::where('id','=',$id)->first();