Skip to content

lumite-studios/model-scopes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lumite-studios/model-scopes

A trait to add various model scopes.

Installation

composer require lumite-studios/model-scopes

Usage

All Scopes

use LumiteStudios\ModelScopes\ModelScopes;

WhereIsModelScope

use LumiteStudios\ModelScopes\WhereIsModelScope;

class User extends Model {
    use WhereIsModelScope;
}
$user = User::first();
$user = User::whereIsModel($user)->first();

WhereHasModelScope

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();