feat: add favorites feature (model, controller, routes, view)

This commit is contained in:
2026-08-18 10:49:10 +03:30
parent 03a0a55630
commit 48705cc940
7 changed files with 198 additions and 1 deletions
+50
View File
@@ -0,0 +1,50 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
* Class Favorite
*
* @property int $id
* @property int $user_id
* @property int $favoritable_id
* @property string $favoritable_type
* @property Carbon $created_at
* @property Carbon $updated_at
*
* @property User $user
*
* @package App\Models
*/
class Favorite extends Model
{
protected $table = 'favorites';
protected $casts = [
'user_id' => 'int',
'favoritable_id' => 'int'
];
protected $fillable = [
'user_id',
'favoritable_id',
'favoritable_type'
];
public function user()
{
return $this->belongsTo(User::class);
}
public function favoritable()
{
return $this->morphTo();
}
}
+4
View File
@@ -98,4 +98,8 @@ class Flight extends Model
{
return $this->belongsTo(Airport::class, 'destination_airports_id');
}
public function favorites()
{
return $this->morphMany(Favorite::class, 'favoritable');
}
}
+4
View File
@@ -74,4 +74,8 @@ class Tour extends Model
{
return $this->hasMany(TourDetail::class);
}
public function favorites()
{
return $this->morphMany(Favorite::class, 'favoritable');
}
}
+4
View File
@@ -72,4 +72,8 @@ class User extends Authenticated
{
return $this->belongsTo(File::class);
}
public function favorites()
{
return $this->hasMany(Favorite::class);
}
}