fix on customer auth, fix filters on shelves, refactor for article_nature, add slug
This commit is contained in:
@@ -82,30 +82,37 @@ trait Basic
|
||||
return self::get($id)->toArray();
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
public static function store($data, $stopStamping = false)
|
||||
{
|
||||
return $data['id'] ?? false ? self::update($data) : self::create($data);
|
||||
return $data['id'] ?? false ? self::update($data, false, $stopStamping) : self::create($data, $stopStamping);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
public static function create($data, $stopStamping = false)
|
||||
{
|
||||
return self::getModel()->create($data);
|
||||
return self::getModel($stopStamping)->create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
public static function update($data, $id = false, $stopStamping = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$model = self::get($id);
|
||||
if ($stopStamping) {
|
||||
$model->stopUserstamping();
|
||||
}
|
||||
$model->update($data);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
public static function destroy($id, $force = false)
|
||||
{
|
||||
$model = self::get($id);
|
||||
|
||||
return $model ? $model->delete() : false;
|
||||
if ($model) {
|
||||
return $force ? $model->forceDelete() : $model->delete();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function count()
|
||||
@@ -125,20 +132,39 @@ trait Basic
|
||||
return $model ? $model->delete() : false;
|
||||
}
|
||||
|
||||
public static function get($id, $relations = false, $relationscount = false)
|
||||
public static function getArray($id, $relations = false, $relationsCount = false)
|
||||
{
|
||||
return self::getModelRelations($relations, $relationscount)->find($id);
|
||||
$model = self::get($id, $relations, $relationsCount);
|
||||
|
||||
return $model ? $model->toArray() : false;
|
||||
}
|
||||
|
||||
public static function getAll($relations = false, $relationscount = false)
|
||||
public static function get($id, $relations = false, $relationsCount = false)
|
||||
{
|
||||
return self::getModelRelations($relations, $relationscount)->get();
|
||||
return self::getModelRelations($relations, $relationsCount)->find($id);
|
||||
}
|
||||
|
||||
public static function getModelRelations($relations = false, $relationscount = false)
|
||||
public static function getWithTrashed($id, $relations = false, $relationsCount = false)
|
||||
{
|
||||
return self::getModelRelations($relations, $relationsCount)->withTrashed()->find($id);
|
||||
}
|
||||
|
||||
public static function getAll($relations = false, $relationsCount = false)
|
||||
{
|
||||
return self::getModelRelations($relations, $relationsCount)->get();
|
||||
}
|
||||
|
||||
public static function getRevisions($id)
|
||||
{
|
||||
$model = self::get($id, ['revisions.user'])->toArray();
|
||||
|
||||
return collect($model['revisions'])->sortBy('created_at')->reverse()->toArray();
|
||||
}
|
||||
|
||||
public static function getModelRelations($relations = false, $relationsCount = false)
|
||||
{
|
||||
$model = $relations ? self::getModelWithRelations($relations) : false;
|
||||
$model = $relationscount ? self::getModelWithCountRelations($relationscount, $model) : $model;
|
||||
$model = $relationsCount ? self::getModelWithCountRelations($relationsCount, $model) : $model;
|
||||
|
||||
return $model ? $model : self::getModel();
|
||||
}
|
||||
@@ -153,8 +179,12 @@ trait Basic
|
||||
return is_object($model) ? $model->withCount($relations) : self::getModel()->withCount($relations);
|
||||
}
|
||||
|
||||
public static function getModel(): Model
|
||||
public static function getModel($stopStamping = false): Model
|
||||
{
|
||||
return new Model();
|
||||
$model = new Model();
|
||||
if ($stopStamping) {
|
||||
$model->stopUserstamping();
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user