change icons, css, add routing to merchandise, add mail templater, fixes

This commit is contained in:
Ludovic CANDELLIER
2023-02-12 23:34:48 +01:00
parent 8313e25f2e
commit f2f4788ce1
71 changed files with 1486 additions and 154 deletions

127
app/Traits/Model/Basic.php Normal file
View File

@@ -0,0 +1,127 @@
<?php
namespace App\Traits\Model;
use Illuminate\Database\Eloquent\Model;
trait Basic
{
public static function toggle($id, $field = 'active')
{
return self::update([$field => ! self::getField($id, $field)], $id);
}
public static function getIDs()
{
return self::getAll()->pluck('id');
}
public static function getOptions($field = 'name')
{
$data = self::getModel()->pluck($field, 'id')->toArray();
asort($data, SORT_NATURAL | SORT_FLAG_CASE);
return $data;
}
public static function getName($id)
{
return self::getField($id, 'name');
}
public static function getByUUID($uuid)
{
return self::getByField('uuid', $uuid)->first();
}
public static function getFields($field)
{
return self::getAll()->pluck($field);
}
public static function getByField($field, $value)
{
return self::getModel()->where($field, $value);
}
public static function getField($id, $field)
{
$model = self::get($id);
return $model ? $model->$field : false;
}
public static function edit($id)
{
return self::get($id)->toArray();
}
public static function store($data)
{
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
}
public static function create($data)
{
return self::getModel()->create($data);
}
public static function update($data, $id = false)
{
$id = $id ? $id : $data['id'];
$model = self::get($id);
$model->update($data);
return $model;
}
public static function destroy($id)
{
$model = self::get($id);
return $model ? $model->delete() : false;
}
public static function count()
{
return self::getModel()->count();
}
public static function firstOrCreate($search, $data)
{
return self::getModel()::firstOrCreate($search, $data);
}
public static function get($id, $relations = false, $relations_count = false)
{
return self::getModelRelations($relations, $relations_count)->find($id);
}
public static function getAll($relations = false, $relations_count = false)
{
return self::getModelRelations($relations, $relations_count)->get();
}
public static function getModelRelations($relations = false, $relations_count = false)
{
$model = $relations ? self::getModelWithRelations($relations) : false;
$model = $relations_count ? self::getModelWithCountRelations($relations_count, $model) : $model;
return $model ? $model : self::getModel();
}
public static function getModelWithRelations($relations = false, $model = false)
{
return is_object($model) ? $model->with($relations) : self::getModel()->with($relations);
}
public static function getModelWithCountRelations($relations = false, $model = false)
{
return is_object($model) ? $model->withCount($relations) : self::getModel()->withCount($relations);
}
public static function getModel(): Model
{
return new Model();
}
}

View File

@@ -35,7 +35,7 @@ trait Imageable
public static function getPreviewSrc($image, $with_undefined = true)
{
return $image ? Medias::getPreviewSrc($image) : ($with_undefined ? '/img/visuel-non-disponible.jpg' : '');
return $image ? Medias::getPreviewSrc($image) : ($with_undefined ? self::getUnknown() : '');
}
public static function getNormal($image, $with_undefined = true)
@@ -46,7 +46,7 @@ trait Imageable
public static function getNormalSrc($image, $with_undefined = true)
{
return $image ? Medias::getNormalSrc($image) : ($with_undefined ? '/img/visuel-non-disponible.jpg' : '');
return $image ? Medias::getNormalSrc($image) : ($with_undefined ? self::getUnknown() : '');
}
public static function getImage($image, $with_undefined = true)
@@ -57,7 +57,12 @@ trait Imageable
public static function getImageSrc($image, $with_undefined = true)
{
return $image ? Medias::getImageSrc($image) : ($with_undefined ? '/img/visuel-non-disponible.jpg' : '');
return $image ? Medias::getImageSrc($image) : ($with_undefined ? self::getUnknown() : '');
}
public static function getUnknown()
{
return '/img/visuel-non-disponible.jpg';
}
public static function deleteImage($id, $index)