mirror of
https://github.com/pacnpal/thrillwiki_laravel.git
synced 2025-12-20 13:51:11 -05:00
Add enums for ReviewStatus, TrackMaterial, LaunchType, RideCategory, and RollerCoasterType; implement Designer and RideModel models; create migrations for ride_models and helpful_votes tables; enhance RideGalleryComponent documentation
This commit is contained in:
45
app/Models/HelpfulVote.php
Normal file
45
app/Models/HelpfulVote.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class HelpfulVote extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'review_id',
|
||||
'user_id',
|
||||
];
|
||||
|
||||
// Relationships
|
||||
public function review(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Review::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
// Helper method to toggle vote
|
||||
public static function toggle(int $reviewId, int $userId): bool
|
||||
{
|
||||
$vote = static::where([
|
||||
'review_id' => $reviewId,
|
||||
'user_id' => $userId,
|
||||
])->first();
|
||||
|
||||
if ($vote) {
|
||||
$vote->delete();
|
||||
return false;
|
||||
}
|
||||
|
||||
static::create([
|
||||
'review_id' => $reviewId,
|
||||
'user_id' => $userId,
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user