“Truques eloqüentes do Laravel” Respostas de código

Truques eloqüentes do Laravel

public function author()
{
    return $this->belongsTo(Author::class)->withDefault();
}
Unsightly Unicorn

Truques eloqüentes do Laravel

// whereRaw
$orders = DB::table('posts')
    ->whereRaw('COUNT(views) > ?', [200])
    ->get();
Unsightly Unicorn

Truques eloqüentes do Laravel


$post = Post::find($id);
$post->views++;
$post->save();
Unsightly Unicorn

Truques eloqüentes do Laravel

$post = Post::first();
$post->title;                   // Something title

$post->title = "new title";    // new title

$user->getOriginal('title');    // Something title
Unsightly Unicorn

Truques eloqüentes do Laravel

public function author()
{
    return $this->belongsTo(Author::class)->withDefault([
        'name' => 'Someone'
    ]);
}
Unsightly Unicorn

Truques eloqüentes do Laravel

$post = Post::create($attributes);

if($post->wasRecentlyCreated) {
  // do something
}
Unsightly Unicorn

Truques eloqüentes do Laravel

// you can increase using
$post = Post::find($id);
$post->increment('views');

// or you can decrease using
$post = Post::find($id);
$post->decrement('views');
Unsightly Unicorn

Respostas semelhantes a “Truques eloqüentes do Laravel”

Perguntas semelhantes a “Truques eloqüentes do Laravel”

Procure respostas de código populares por idioma

Procurar outros idiomas de código