Trucos elocuentes de Laravel
public function author()
{
return $this->belongsTo(Author::class)->withDefault();
}
Unsightly Unicorn
public function author()
{
return $this->belongsTo(Author::class)->withDefault();
}
// whereRaw
$orders = DB::table('posts')
->whereRaw('COUNT(views) > ?', [200])
->get();
$post = Post::find($id);
$post->views++;
$post->save();
$post = Post::first();
$post->title; // Something title
$post->title = "new title"; // new title
$user->getOriginal('title'); // Something title
public function author()
{
return $this->belongsTo(Author::class)->withDefault([
'name' => 'Someone'
]);
}
$post = Post::create($attributes);
if($post->wasRecentlyCreated) {
// do something
}
// you can increase using
$post = Post::find($id);
$post->increment('views');
// or you can decrease using
$post = Post::find($id);
$post->decrement('views');