feat: Multiple Systems

This commit is contained in:
2024-03-18 01:26:54 +01:00
parent 22ea1930c4
commit 12d8f3913c
29 changed files with 2556 additions and 90 deletions

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class BookRecommendation extends Model
{
protected $table = 'book_recommendations';
protected $fillable = [
'book_name',
'author',
'description',
'isbn',
'pages',
'recommended_by',
'cover_image',
'status',
];
/**
* Get the user that recommended the book.
*/
public function recommender()
{
return $this->belongsTo(User::class, 'recommended_by');
}
public function votes()
{
return $this->hasMany(Vote::class);
}
}

View File

@@ -24,6 +24,7 @@ class User extends Authenticatable implements MustVerifyEmail
'email',
'avatar',
'password',
'total_votes',
];
/**
@@ -57,6 +58,11 @@ class User extends Authenticatable implements MustVerifyEmail
return $this->hasMany(UserProvider::class);
}
public function votes()
{
return $this->hasMany(Vote::class);
}
public function mustVerifyEmail(): bool
{
return $this instanceof MustVerifyEmail && !$this->hasVerifiedEmail();

26
app/Models/Vote.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Vote extends Model
{
use HasFactory;
protected $fillable = [
'user_id',
'book_recommendation_id',
];
public function user()
{
return $this->belongsTo(User::class);
}
public function bookRecommendation()
{
return $this->belongsTo(BookRecommendation::class);
}
}