Laravel5.4 使用 tinker 对文章模型的增删改查

浏览573

Laravel5.4 使用 tinker 对文章模型的增删改查

1、创建文章模型: 

php artisan make:model Art

image.png

2、打开 tinker

php artisan tinker

image.png

3、创建文章:

$art=new \App\Art();
App\Art {#706}
$art->title ="this is art1";
"this is art1"
$art->content="this is art1 content";
"this is art1 content"
$art->save();
true

4、查询文章:

4.1根据id查询文章

\App\art::find(2);

image.png

4.1根据标题查询文章

\App\Art::where('title','this is title2')->first();

image.png

\App\Art::where('title','this is title2')->get();

image.png

5、文章删除:

$art = \App\Art::find(2);
$art->delete();

image.png


  • 暂无任何回答