mirror of
https://github.com/Cybrarist/Discount-Bandit.git
synced 2026-11-24 19:49:54 +01:00
67 lines
1.6 KiB
PHP
67 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\ProductStatusEnum;
|
|
use App\Models\Scopes\UserOwnedScope;
|
|
use Database\Factories\ProductFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\ScopedBy;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
#[ScopedBy(UserOwnedScope::class)]
|
|
class Product extends Model
|
|
{
|
|
/** @use HasFactory<ProductFactory> */
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'image',
|
|
'status',
|
|
'user_id',
|
|
'is_favourite',
|
|
'is_in_stock',
|
|
'snoozed_until',
|
|
'max_notifications_daily',
|
|
'lowest_price',
|
|
'highest_price',
|
|
'notifications_sent',
|
|
'remove_link_if_out_of_stock_for_x_days',
|
|
'is_list',
|
|
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'snoozed_until' => 'date',
|
|
'is_favourite' => 'boolean',
|
|
'is_in_stock' => 'boolean',
|
|
'status' => ProductStatusEnum::class,
|
|
];
|
|
}
|
|
|
|
public function links(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Link::class)
|
|
->withTimestamps()
|
|
->withPivot([
|
|
'user_id',
|
|
]);
|
|
}
|
|
|
|
public function categories(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Category::class)
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
}
|