Pharaonic
Loading...

# User Model

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

# Inclusion

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

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

# review

This is how you can create a new review to the $course model through User model.

1// Model
2// Rate
3// Comment (OPTIONAL)
4$user->review($course, 4.5, 'Review Text Here');
5// Returns Boolean

# unreview

This is how you can unreview the $course model through User model.

1$user->unreview($course);
2// Returns Boolean

# reviewed

This is how you can check the $course model that has been reviewed by User model.

1if($user->reviewed($course)) {
2 //
3}

# Reviewable Model

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

# Inclusion

You have to include the isReviewable trait into the Model.

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

# reviewBy

This is how you can create a new review to the $course model.

1// Model
2// Rate
3// Comment (OPTIONAL)
4$course->reviewBy($user, 4.5, 'Review Text Here');
5// Returns Boolean

# unreviewBy

This is how you can unreview the $course model.

1$course->unreviewBy($user);
2// Returns Boolean

# reviewedBy

This is how you can check the $course model that has been reviewed.

1if($course->reviewedBy($user)) {
2 //
3}

# Ratings Value

This is how you can get the average ratings of $course model.

1echo $course->rating;
2// Returns Float

# Relationships

  • reviews
    • reviewer
    • reviewable