¨4.0.1¨
This commit is contained in:
@@ -11,13 +11,18 @@ class Slider extends Model
|
||||
{
|
||||
use Translatable;
|
||||
|
||||
/**
|
||||
* The attributes that are translatable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $translatedAttributes = ['name'];
|
||||
/**
|
||||
* The relations to eager load on every query.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $with = ['translations', 'slides'];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
@@ -25,12 +30,19 @@ class Slider extends Model
|
||||
*/
|
||||
protected $fillable = ['speed', 'autoplay', 'autoplay_speed', 'fade', 'dots', 'arrows'];
|
||||
|
||||
/**
|
||||
* The attributes that are translatable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $translatedAttributes = ['name'];
|
||||
|
||||
public static function findWithSlides($id)
|
||||
{
|
||||
if (is_null($id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return Cache::tags("sliders.{$id}")
|
||||
->rememberForever(md5("sliders.{$id}:" . locale()), function () use ($id) {
|
||||
return static::with('slides')->find($id);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
@@ -45,47 +57,12 @@ class Slider extends Model
|
||||
});
|
||||
}
|
||||
|
||||
public function shouldAutoPlay()
|
||||
{
|
||||
return $this->autoplay ? 'true' : 'false';
|
||||
}
|
||||
|
||||
public function clearCache()
|
||||
{
|
||||
Cache::tags("sliders.{$this->id}")->flush();
|
||||
}
|
||||
|
||||
public static function findWithSlides($id)
|
||||
{
|
||||
if (is_null($id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return Cache::tags("sliders.{$id}")
|
||||
->rememberForever(md5("sliders.{$id}:" . locale()), function () use ($id) {
|
||||
return static::with('slides')->find($id);
|
||||
});
|
||||
}
|
||||
|
||||
public function slides()
|
||||
{
|
||||
return $this->hasMany(SliderSlide::class)->orderBy('position');
|
||||
}
|
||||
|
||||
public function getAutoplaySpeedAttribute($autoplaySpeed)
|
||||
{
|
||||
return $autoplaySpeed ?: 3000;
|
||||
}
|
||||
|
||||
public function table()
|
||||
{
|
||||
return new AdminTable($this->newQuery());
|
||||
}
|
||||
|
||||
/**
|
||||
* Save slides for the slider.
|
||||
*
|
||||
* @param array $slides
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function saveSlides($slides)
|
||||
@@ -104,6 +81,43 @@ class Slider extends Model
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function slides()
|
||||
{
|
||||
return $this->hasMany(SliderSlide::class)->orderBy('position');
|
||||
}
|
||||
|
||||
|
||||
public function clearCache()
|
||||
{
|
||||
Cache::tags("sliders.{$this->id}")->flush();
|
||||
}
|
||||
|
||||
|
||||
public function shouldAutoPlay()
|
||||
{
|
||||
return $this->autoplay ? 'true' : 'false';
|
||||
}
|
||||
|
||||
|
||||
public function getSpeedAttribute($speed)
|
||||
{
|
||||
return $speed ?: 1000;
|
||||
}
|
||||
|
||||
|
||||
public function getAutoplaySpeedAttribute($autoplaySpeed)
|
||||
{
|
||||
return $autoplaySpeed ?: 3000;
|
||||
}
|
||||
|
||||
|
||||
public function table()
|
||||
{
|
||||
return new AdminTable($this->newQuery());
|
||||
}
|
||||
|
||||
|
||||
private function getDeleteCandidates($slides = [])
|
||||
{
|
||||
return $this->slides()
|
||||
|
||||
Reference in New Issue
Block a user