Pharaonic
Loading...

# User Model

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

# Inclusion

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

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

# favourite

This is how you can create a new favorite to the $product model through User model.

1$user->favourite($product);
2// Returns Boolean

# unfavourite

This is how you can unfavorite the $product model through User model.

1$user->unfavourite($product);
2// Returns Boolean

# favoured

This is how you can check the $product model that has been favoured by User model.

1if($user->favoured($product)) {
2 //
3}

# Favourable Model

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

# Inclusion

You have to include the isFavourable trait into the Model.

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

# favouriteBy

This is how you can create a new favorite to the $product model.

1$product->favouriteBy($user);
2// Returns Boolean

# unfavouriteBy

This is how you can unfavorite the $product model.

1$product->unfavouriteBy($user);
2// Returns Boolean

# favouredBy

This is how you can check the $product model that has been favoured.

1if($product->favouredBy($user)) {
2 //
3}

# Relationships

  • favourites
    • favorer
    • favourable