A trait to add various model scopes.
composer require lumite-studios/model-scopes
use LumiteStudios\ModelScopes\ModelScopes;
use LumiteStudios\ModelScopes\WhereIsModelScope;
class User extends Model {
use WhereIsModelScope;
}
$user = User::first();
$user = User::whereIsModel($user)->first();
use LumiteStudios\ModelScopes\WhereHasModelScope;
class Post extends Model {
use WhereHasModelScope;
public function user()
{
return $this->belongsTo(User::class);
}
}
class User extends Model {
use WhereHasModelScope;
public function posts()
{
return $this->hasMany(Post::class);
}
}
$user = User::first();
$posts = Post::whereHasModel('user', $user)->get();
$post = Post::first();
$user = User::whereHasModel('posts', $post)->first();