<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
protonemedia / laravel-eloquent-where-not example snippets
use ProtoneMedia\LaravelEloquentWhereNot\WhereNot;
public function boot()
{
WhereNot::addMacro();
// or use a custom method name:
WhereNot::addMacro('not');
}
class Post extends Model
{
public function user()
{
return $this->belongsTo(User::class);
}
public function comments()
{
return $this->hasMany(Comment::class);
}
public function scopeOnFrontPage($query)
{
$query->where('is_public', 1)
->where('votes', '>', 100)
->has('comments', '>=', 20)
->whereHas('user', fn($user) => $user->isAdmin())
->whereYear('published_at', date('Y'));
}
}