40 lines
899 B
PHP
40 lines
899 B
PHP
<?php
|
|
|
|
namespace App\Models\Botanic;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Wildside\Userstamps\Userstamps;
|
|
|
|
class Genre extends Model
|
|
{
|
|
use SoftDeletes, Userstamps;
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected $table = 'botanic_genres';
|
|
|
|
public function family(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Family::class);
|
|
}
|
|
|
|
public function species(): HasMany
|
|
{
|
|
return $this->hasMany(Specie::class);
|
|
}
|
|
|
|
public function varieties(): HasManyThrough
|
|
{
|
|
return $this->hasManyThrough(Variety::class, Specie::class);
|
|
}
|
|
|
|
public function scopeByName($query, $name)
|
|
{
|
|
return $query->where('name', $name);
|
|
}
|
|
}
|