Pharaonic
Loading...

# User Model

This is the primary way that you can use to create a new bookmark to the model through User Model.

# Inclusion

You have to include the isBookmarker trait into the User Model.

1namespace App\Models;
2 
3use Illuminate\Foundation\Auth\User as Authenticatable;
4use Pharaonic\Laravel\Users\Traits\Actions\Bookmark\isBookmarker;
5 
6class User extends Authenticatable
7{
8 use isBookmarker;
9 
10 protected $fillable = ['name', 'email', 'password'];
11}

# bookmark

This is how you can create a new bookmark to the $book model through User model.

1$user->bookmark($book);
2// Returns Boolean
3 
4// data [array] (OPTIONAL)
5$user->bookmark($book, [
6 'page' => 2,
7 'line' => 8
8]);

# unbookmark

This is how you can unbookmark the $book model through User model.

1$user->unbookmark($book);
2// Returns Boolean

# bookmarked

This is how you can check the $book model that has been bookmarked by User model.

1if($user->bookmarked($book)) {
2 //
3}

# Bookmarkable Model

This is the secondary way that you can use to create a new bookmark to the model.

# Inclusion

You have to include the isBookmarkable trait into the Model.

1namespace App\Models;
2 
3use Illuminate\Database\Eloquent\Model;
4use Pharaonic\Laravel\Users\Traits\Actions\Bookmark\isBookmarkable;
5 
6class Book extends Model
7{
8 use isBookmarkable;
9 
10 protected $fillable = ['title'];
11}

# bookmarkBy

This is how you can create a new bookmark to the $book model.

1$book->bookmarkBy($user);
2// Returns Boolean
3 
4// data [array] (OPTIONAL)
5$book->bookmarkBy($user, [
6 'page' => 2,
7 'line' => 8
8]);

# unbookmarkBy

This is how you can unbookmark the $book model.

1$book->unbookmarkBy($user);
2// Returns Boolean

# bookmarkedBy

This is how you can check the $book model that has been bookmarked.

1if($book->bookmarkedBy($user)) {
2 //
3}

# Relationships

  • bookmarks
    • bookmarker
    • bookmarkable