[WIP] Add some classes

This commit is contained in:
Ludovic CANDELLIER
2020-04-25 01:06:04 +02:00
parent e0fecd1a6e
commit 516ec2232e
36 changed files with 814 additions and 131 deletions

View File

@@ -3,9 +3,12 @@
namespace App\Models\Botanic;
use Illuminate\Database\Eloquent\Model;
use \Staudenmeir\EloquentHasManyDeep\HasRelationships;
class Family extends Model
{
use HasRelationships;
protected $guarded = ['id'];
protected $table = 'botanic_families';
@@ -14,6 +17,16 @@ class Family extends Model
return $this->hasMany('App\Models\Botanic\Genre');
}
public function species()
{
return $this->hasManyThrough('App\Models\Botanic\Specie', 'App\Models\Botanic\Genre');
}
public function varieties()
{
return $this->hasManyDeep('App\Models\Botanic\Variety', ['App\Models\Botanic\Genre', 'App\Models\Botanic\Specie']);
}
public function scopeByName($query,$name)
{
return $query->where('name', $name);

View File

@@ -19,6 +19,11 @@ class Genre extends Model
return $this->hasMany('App\Models\Botanic\Specie');
}
public function varieties()
{
return $this->hasManyThrough('App\Models\Botanic\Variety', 'App\Models\Botanic\Specie');
}
public function scopeByName($query,$name)
{
return $query->where('name', $name);