1$post = Post::first();
2$post->title; // Something title
3
4$post->title = "new title"; // new title
5
6$user->getOriginal('title'); // Something title
1// whereRaw
2$orders = DB::table('posts')
3 ->whereRaw('COUNT(views) > ?', [200])
4 ->get();
1// you can increase using
2$post = Post::find($id);
3$post->increment('views');
4
5// or you can decrease using
6$post = Post::find($id);
7$post->decrement('views');
8
1public function author()
2{
3 return $this->belongsTo(Author::class)->withDefault();
4}
1$post = Post::create($attributes);
2
3if($post->wasRecentlyCreated) {
4 // do something
5}
1public function author()
2{
3 return $this->belongsTo(Author::class)->withDefault([
4 'name' => 'Someone'
5 ]);
6}