/home/bdqbpbxa/dev-subdomains/api-uniferx.goodface.com.ua/app/Models/Crop.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
class Crop extends Model
{
use HasFactory;
protected $table = 'crops';
protected $fillable = [
'slug',
'title',
'title_image',
'icon',
'detailed',
'trial_countries',
'trials',
'is_enabled',
'fs_background',
'fs_view_button',
'sidebar_text',
];
protected $casts = [
'detailed' => 'array',
'trials' => 'array',
'trial_countries' => 'array',
'icon' => 'array',
'fs_background' => 'array',
'fs_view_button' => 'array',
'title_image' => 'array',
'sidebar_text' => 'array',
];
public function countries()
{
return $this->belongsToMany(
Country::class,
'crop_countries',
);
}
public function nutrition_products()
{
return $this->belongsToMany(
Product::class,
'product_nutrition_program',
'crop_id',
'product_id',
);
}
public function trial_products()
{
return $this->belongsToMany(
Product::class,
'product_trial_result',
'crop_id',
'product_id',
);
}
public function flyers(): MorphToMany
{
return $this->morphToMany(Flyer::class, 'flyerables')->withPivot('product_id')->orderByPivot('id');
}
}