Laravel eloquent tricks
public function author()
{
return $this->belongsTo(Author::class)->withDefault();
}
Laravel eloquent tricks
public function author()
{
return $this->belongsTo(Author::class)->withDefault();
}
Laravel eloquent tricks
$post = Post::create($attributes);
if($post->wasRecentlyCreated) {
// do something
}
Laravel eloquent tricks
public function author()
{
return $this->belongsTo(Author::class)->withDefault([
'name' => 'Someone'
]);
}
Laravel eloquent tricks
$post = Post::find($id);
$post->views++;
$post->save();
Laravel eloquent tricks
$post = Post::first();
$post->title; // Something title
$post->title = "new title"; // new title
$user->getOriginal('title'); // Something title
Laravel eloquent tricks
// whereRaw
$orders = DB::table('posts')
->whereRaw('COUNT(views) > ?', [200])
->get();
Laravel eloquent tricks
// you can increase using
$post = Post::find($id);
$post->increment('views');
// or you can decrease using
$post = Post::find($id);
$post->decrement('views');
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us