laravel5.4开发笔记(二)
以下是有关laravel框架的部分总结
如果有任何问题和以为欢迎留言
代码都是调试过没有问题的
都是数据库的相关操作
数据操作
1.添加数据操作
cmd给数据库表post添加内容:
>>> $post = new /App/Post(); PHP Parse error: Syntax error, unexpected '/' on line 1 >>> $post = new \App\Post(); => App\Post {#651} >>> $post->title = "this is post1"; => "this is post1" >>> $post->content = "this is post1 content"; => "this is post1 content" >>> $post->save(); => true >>>
数据表结果:
时区设置:UTC改成Asia/Shanghai然后重启tinker
2.查询操作
查询id为2的数据:
>>> \App\Post::find(2); => App\Post {#666 id: 2, title: "this is post2", content: "this is post2 content", user_id: 0, created_at: "2017-08-22 03:49:05", updated_at: "2017-08-22 03:49:05", } >>>
条件查询where:
>>> \App\Post::where('title','this is post1')->first(); => App\Post {#671 id: 1, title: "this is post1", content: "this is post1 content", user_id: 0, created_at: "2017-08-22 03:35:14", updated_at: "2017-08-22 03:35:14", } >>>
get()方法返回的是一个对象:
>>> \App\Post::where('title','this is post1')->get(); => Illuminate\Database\Eloquent\Collection {#664 all: [ App\Post {#667 id: 1, title: "this is post1", content: "this is post1 content", user_id: 0, created_at: "2017-08-22 03:35:14", updated_at: "2017-08-22 03:35:14", }, ], } >>>
3.修改操作
修改id为2的表数据
>>> $post = \App\Post::find(2); => App\Post {#670 id: 2, title: "this is post2", content: "this is post2 content", user_id: 0, created_at: "2017-08-22 03:49:05", updated_at: "2017-08-22 03:49:05", } >>> $post->title = 'this is post2new'; => "this is post2new" >>> $post->save(); => true
4.删除操作
删除id为2的数据
>>> $post = \App\Post::find(2); => App\Post {#666 id: 2, title: "this is post2new", content: "this is post2 content", user_id: 0, created_at: "2017-08-22 03:49:05", updated_at: "2017-08-22 12:06:54", } >>> $post->delete(); => true >>>
续:请看laravel5.4开发笔记(三)
本文由
wilkins创作
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: 2018-03-15 11
*更多学习视频资料请关照博主的星球,扫一扫下方的星球二维码加入

*更多区块链技术视频资料请关照博主的星球,扫一扫下方的星球二维码加入

*喜欢本文章觉得有帮助的话,扫个打赏码,给博主打赏个买菜钱$

www.changfengpolang.com
网址不行
想问一下这个网页前端是用框架写的吗?
不是