Add relations in tables, add saving states for datatables, minor fixes

This commit is contained in:
Ludovic CANDELLIER
2021-09-14 23:14:03 +02:00
parent 1dcc3e34a9
commit ffb9f81353
16 changed files with 255 additions and 47 deletions

View File

@@ -15,6 +15,11 @@ class Specie extends Model
protected $guarded = ['id'];
protected $table = 'botanic_species';
public function tags()
{
return $this->morphToMany('App\Models\Shop\Tag', 'taggable');
}
public function Genre()
{
return $this->belongsTo('App\Models\Botanic\Genre');

View File

@@ -31,6 +31,11 @@ class Variety extends Model implements HasMedia
return $this->morphMany('App\Models\Shop\Article', 'product');
}
public function tags()
{
return $this->morphToMany('App\Models\Shop\Tag', 'taggable');
}
public function registerMediaConversions(Media $media = null) : void
{
$this->addMediaConversion('thumb')->fit(Manipulations::FIT_CROP, 32, 32);

View File

@@ -40,11 +40,6 @@ class Article extends Model implements HasMedia
return $this->hasOne('App\Models\Core\Media', 'model_id')->where('model_type', 'App\Models\Shop\Article');
}
public function inventories()
{
return $this->hasMany('App\Models\Shop\Inventory');
}
public function invoiceItems()
{
return $this->hasMany('App\Models\Shop\InvoiceItem');
@@ -60,6 +55,11 @@ class Article extends Model implements HasMedia
return $this->morphTo();
}
public function tags()
{
return $this->morphToMany('App\Models\Shop\Tag', 'taggable');
}
public function scopeByArticle($query, $id)
{
return $query->where($this->table . '.id', $id);

View File

@@ -8,7 +8,29 @@ class Tag extends Model
{
protected $guarded = ['id'];
public $translatable = ['name'];
public $translatable = ['name'];
/*
public function taggable()
{
return $this->hasMany('App\Models\Shop\Taggable');
}
*/
public function articles()
{
return $this->morphedByMany('App\Models\Shop\Article','taggable');
}
public function varieties()
{
return $this->morphedByMany('App\Models\Botanic\Variety','taggable');
}
public function species()
{
return $this->morphedByMany('App\Models\Botanic\Specie','taggable');
}
public function group()
{

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class Taggable extends Model
{
protected $guarded = ['id'];
public function taggable()
{
return $this->morphTo();
}
}