¨4.0.1¨
This commit is contained in:
@@ -7,6 +7,25 @@ use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
|
||||
abstract class Model extends Eloquent
|
||||
{
|
||||
public static function queryWithoutEagerRelations()
|
||||
{
|
||||
return (new static)->newQueryWithoutEagerRelations();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register a new active global scope on the model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function addActiveGlobalScope()
|
||||
{
|
||||
static::addGlobalScope('active', function ($query) {
|
||||
$query->where('is_active', true);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform any actions required before the model boots.
|
||||
*
|
||||
@@ -23,10 +42,6 @@ abstract class Model extends Eloquent
|
||||
});
|
||||
}
|
||||
|
||||
public static function queryWithoutEagerRelations()
|
||||
{
|
||||
return (new static)->newQueryWithoutEagerRelations();
|
||||
}
|
||||
|
||||
public function newQueryWithoutEagerRelations()
|
||||
{
|
||||
@@ -35,20 +50,9 @@ abstract class Model extends Eloquent
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function clearEntityTaggedCache()
|
||||
{
|
||||
Cache::tags($this->getTable())->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new active global scope on the model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function addActiveGlobalScope()
|
||||
{
|
||||
static::addGlobalScope('active', function ($query) {
|
||||
$query->where('is_active', true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,12 @@ trait Sluggable
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the slug attribute.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setSlug($value = null)
|
||||
@@ -33,10 +35,12 @@ trait Sluggable
|
||||
$this->attributes['slug'] = $this->generateSlug($value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate slug by the given value.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateSlug($value)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Modules\Support\Eloquent;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Astrotomic\Translatable\Translatable as AstrotomicTranslatable;
|
||||
|
||||
trait Translatable
|
||||
@@ -12,6 +13,7 @@ trait Translatable
|
||||
* Save the model to the database.
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function save(array $options = [])
|
||||
@@ -23,20 +25,22 @@ trait Translatable
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This scope filters results by checking the translation fields.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param Builder $query
|
||||
* @param string $key
|
||||
* @param array $values
|
||||
* @param string $locale
|
||||
* @return \Illuminate\Database\Eloquent\Builder|static
|
||||
*
|
||||
* @return Builder|static
|
||||
*/
|
||||
public function scopeWhereTranslationIn($query, $key, array $values, $locale = null)
|
||||
{
|
||||
return $query->whereHas('translations', function ($query) use ($key, $values, $locale) {
|
||||
$query->whereIn($key, $values)
|
||||
->when(! is_null($locale), function ($query) use ($locale) {
|
||||
->when(!is_null($locale), function ($query) use ($locale) {
|
||||
$query->where('locale', $locale);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,6 +13,7 @@ abstract class TranslationModel extends Model
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
|
||||
/**
|
||||
* Perform any actions required before the model boots.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user