|
|
@ -57,16 +57,18 @@ use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class Cat extends Model implements HasMedia
|
|
|
|
class Cat extends Model implements HasMedia
|
|
|
|
{
|
|
|
|
{
|
|
|
|
use HasFactory,SoftDeletes, InteractsWithMedia;
|
|
|
|
use HasFactory, SoftDeletes, InteractsWithMedia;
|
|
|
|
|
|
|
|
|
|
|
|
public function registerMediaConversions(Media $media = null): void
|
|
|
|
public function registerMediaConversions(Media $media = null): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$size = explode('x', config('app.thumbnail_size'));
|
|
|
|
|
|
|
|
|
|
|
|
$this->addMediaConversion('cat-thumb')
|
|
|
|
$this->addMediaConversion('cat-thumb')
|
|
|
|
->width(600)
|
|
|
|
->width($size[0])
|
|
|
|
->height(600)
|
|
|
|
->height($size[1])
|
|
|
|
->crop(Manipulations::CROP_CENTER, 600, 600)
|
|
|
|
->crop(Manipulations::CROP_CENTER, $size[0], $size[1])
|
|
|
|
->optimize()
|
|
|
|
->optimize()
|
|
|
|
->sharpen(10);
|
|
|
|
->sharpen(10);
|
|
|
|
|
|
|
|
|
|
|
@ -75,7 +77,8 @@ class Cat extends Model implements HasMedia
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function thumbUrl() {
|
|
|
|
public function thumbUrl()
|
|
|
|
|
|
|
|
{
|
|
|
|
if ($this->getMedia()->count() > 0) {
|
|
|
|
if ($this->getMedia()->count() > 0) {
|
|
|
|
return $this->getMedia()->first()->getUrl('cat-thumb');
|
|
|
|
return $this->getMedia()->first()->getUrl('cat-thumb');
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -84,7 +87,8 @@ class Cat extends Model implements HasMedia
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function imgurl() {
|
|
|
|
public function imgurl()
|
|
|
|
|
|
|
|
{
|
|
|
|
if ($this->getMedia()->count() > 0) {
|
|
|
|
if ($this->getMedia()->count() > 0) {
|
|
|
|
return $this->getMedia()->last()->getUrl();
|
|
|
|
return $this->getMedia()->last()->getUrl();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -92,11 +96,14 @@ class Cat extends Model implements HasMedia
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function products(){
|
|
|
|
public function products()
|
|
|
|
return$this->belongsToMany(Product::class);
|
|
|
|
{
|
|
|
|
|
|
|
|
return $this->belongsToMany(Product::class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function active_products(){
|
|
|
|
|
|
|
|
return$this->belongsToMany(Product::class)->where('');
|
|
|
|
public function active_products()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return $this->belongsToMany(Product::class)->where('active', 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function backUrl()
|
|
|
|
public function backUrl()
|
|
|
@ -109,19 +116,23 @@ class Cat extends Model implements HasMedia
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
public function parent() {
|
|
|
|
public function parent()
|
|
|
|
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Cat::class, 'parent_id');
|
|
|
|
return $this->belongsTo(Cat::class, 'parent_id');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function children() {
|
|
|
|
public function children()
|
|
|
|
|
|
|
|
{
|
|
|
|
return $this->hasMany(Cat::class, 'parent_id');
|
|
|
|
return $this->hasMany(Cat::class, 'parent_id');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getRouteKeyName() {
|
|
|
|
public function getRouteKeyName()
|
|
|
|
|
|
|
|
{
|
|
|
|
return 'slug';
|
|
|
|
return 'slug';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function props(){
|
|
|
|
public function props()
|
|
|
|
|
|
|
|
{
|
|
|
|
return $this->belongsToMany(Prop::class);
|
|
|
|
return $this->belongsToMany(Prop::class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|