Laravel 5 |用以前的记录覆盖记录Ubuntu的

时间:2016-02-11 05:27:12

标签: php laravel eloquent laravel-5.2

在我的代码中, 我尝试用“php artisan tinker”一次添加多条记录。

MY INPUT:

  $tag = new App\tags
     => App\tags {#666}
  $tag->name = 'General'
     => "General"
  $tag->save()
     => true

然后我得到了,

  App\tags::get()
  => Illuminate\Database\Eloquent\Collection {#696
 all: [
   App\tags {#702
     id: "7",
     name: "General",
     created_at: "2016-02-11 05:18:33",
     updated_at: "2016-02-11 05:18:33",
   },
 ],
 }

我添加另一个后,

$tag->name = 'Private'
=> "Private"
$tag->save()
=> true

然后我又来了,

App\tags::get()
   => Illuminate\Database\Eloquent\Collection {#694
 all: [
   App\tags {#692
     id: "7",
     name: "Private",
     created_at: "2016-02-11 10:48:59",
     updated_at: "2016-02-11 05:18:59",
   },
 ],
}

此外,我尝试“:: all()”,我得到相同的结果。

我的代码出了什么问题。

1 个答案:

答案 0 :(得分:3)

在设置$tag->name = 'Private'

之前,您没有创建新标记

首先再次运行$tag = new App\tags