<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class Item extends Model
{
    use HasFactory;

    public function getRouteKeyName()
    {
        return 'slug';
    }

    /**
     * Set the slug.
     *
     * @param  string  $value
     * @return void
     */
    public function setSlugAttribute($value)
    {
        $this->attributes['slug'] = Str::slug($value, '-');
    }

    public function category()
    {
        return $this->belongsTo('App\Models\Category');
    }

    public function favorite()
    {
        return $this->hasMany(Favorite::class);
    }

    public function review()
    {
        return $this->hasMany(Review::class);
    }

    
}
