add kwaadpepper/crud-policies
add composer.lock file
This commit is contained in:
parent
c6ffadae35
commit
23501c404b
99 changed files with 9717 additions and 2331 deletions
|
|
@ -1,49 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Kwaadpepper\Enum\BaseEnum;
|
||||
|
||||
/**
|
||||
*
|
||||
* https://laravel.com/docs/8.x/authorization
|
||||
* Controller Method Policy Method
|
||||
* index viewAny
|
||||
* show view
|
||||
* create create
|
||||
* store create
|
||||
* edit update
|
||||
* update update
|
||||
* destroy delete
|
||||
*
|
||||
* @method static self viewAny()
|
||||
* @method static self view()
|
||||
* @method static self create()
|
||||
* @method static self update()
|
||||
* @method static self delete()
|
||||
*/
|
||||
|
||||
class CrudAction extends BaseEnum
|
||||
{
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
'viewAny' => 0,
|
||||
'view' => 1,
|
||||
'create' => 2,
|
||||
'update' => 3,
|
||||
'delete' => 4,
|
||||
];
|
||||
}
|
||||
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'viewAny' => trans('Liste'),
|
||||
'view' => trans('Voir'),
|
||||
'create' => trans('Créer'),
|
||||
'update' => trans('Éditer'),
|
||||
'delete' => trans('Supprimer'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Kwaadpepper\Enum\BaseEnum;
|
||||
|
||||
/**
|
||||
* @method static self boolean()
|
||||
* @method static self int()
|
||||
* @method static self string()
|
||||
* @method static self text()
|
||||
* @method static self json()
|
||||
* @method static self image()
|
||||
* @method static self email()
|
||||
* @method static self password()
|
||||
* @method static self float()
|
||||
* @method static self enum()
|
||||
* @method static self belongsTo()
|
||||
* @method static self belongsToMany()
|
||||
*/
|
||||
|
||||
class CrudType extends BaseEnum
|
||||
{
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
'boolean' => 0,
|
||||
'int' => 1,
|
||||
'string' => 2,
|
||||
'text' => 3,
|
||||
'json' => 4,
|
||||
'image' => 5,
|
||||
'email' => 6,
|
||||
'password' => 7,
|
||||
'float' => 8,
|
||||
'enum' => 9,
|
||||
'belongsTo' => 10,
|
||||
'belongsToMany' => 11
|
||||
];
|
||||
}
|
||||
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'boolean' => trans('Booléen'),
|
||||
'int' => trans('Nombre'),
|
||||
'string' => trans('Chaîne de charactères simple'),
|
||||
'text' => trans('Texte'),
|
||||
'json' => trans('Json'),
|
||||
'image' => trans('Image'),
|
||||
'email' => trans('Chaîne de charactères email'),
|
||||
'password' => trans('Mot de passe'),
|
||||
'float' => trans('Nombre à virgule flotante'),
|
||||
'enum' => trans('Énumération'),
|
||||
'belongsTo' => trans('Clé étrangère'),
|
||||
'belongsToMany' => trans('Relation Belongs To Many')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class CrudException extends Exception
|
||||
{
|
||||
}
|
||||
|
|
@ -1,262 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\CrudType;
|
||||
use App\Exceptions\CrudException;
|
||||
use App\Http\Requests\CrudIndexRequest;
|
||||
use App\Http\Requests\StoreCrudModel;
|
||||
use App\Http\Requests\UpdateCrudModel;
|
||||
use App\Http\Resources\CrudResource;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CrudController extends Controller
|
||||
{
|
||||
|
||||
/** @var \Illuminate\Database\Eloquent\Model */
|
||||
protected static $modelClass = null;
|
||||
|
||||
// Eloquent callbacks
|
||||
public function indexQuery(Builder $query): Builder
|
||||
{
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function storeModel(Model &$model)
|
||||
{
|
||||
}
|
||||
|
||||
public function storedModel(Model &$model)
|
||||
{
|
||||
}
|
||||
|
||||
public function updateModel(Model &$model)
|
||||
{
|
||||
}
|
||||
|
||||
public function updatedModel(Model &$model)
|
||||
{
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// AUTH CONTROL TO ROOT POLICY
|
||||
$this->authorizeResource(static::$modelClass);
|
||||
|
||||
$modelClass = static::$modelClass;
|
||||
if (is_null($modelClass) or !class_exists($modelClass)) {
|
||||
throw new CrudException(sprintf(
|
||||
'%s needs the modelClass prop to be a class, %s %s given',
|
||||
__CLASS__,
|
||||
gettype($modelClass),
|
||||
$modelClass
|
||||
));
|
||||
}
|
||||
if (!is_subclass_of($modelClass, Model::class)) {
|
||||
throw new CrudException(sprintf(
|
||||
'%s needs the model prop to be a class the extends %s',
|
||||
__CLASS__,
|
||||
Model::class
|
||||
));
|
||||
}
|
||||
if (!request()->ajax() and !app()->runningInConsole()) {
|
||||
self::shareCrudModelsClassesToView();
|
||||
$this->shareModelClassToView();
|
||||
$this->shareModelHasImageToView();
|
||||
$this->shareModelTableToView();
|
||||
$this->shareModelPropsToView();
|
||||
}
|
||||
}
|
||||
|
||||
public function index(CrudIndexRequest $request)
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder */
|
||||
$models = static::$modelClass::query();
|
||||
|
||||
// Search on crud Label column
|
||||
if ($request->search) {
|
||||
$model = static::$modelClass;
|
||||
$col = (new $model())->crudLabelColumn;
|
||||
$models = $models->where($col, 'LIKE', "%$request->search%");
|
||||
}
|
||||
|
||||
// Sort columns
|
||||
$tableName = (new static::$modelClass())->getTable();
|
||||
if ($request->rst) {
|
||||
Session::remove("crud.$tableName.sort_col");
|
||||
Session::remove("crud.$tableName.sort_way");
|
||||
}
|
||||
if ($request->sort_col) {
|
||||
Session::put("crud.$tableName.sort_col", $request->sort_col);
|
||||
Session::save();
|
||||
}
|
||||
if ($request->sort_way) {
|
||||
Session::put("crud.$tableName.sort_way", $request->sort_way);
|
||||
Session::save();
|
||||
}
|
||||
|
||||
if (
|
||||
Session::has("crud.$tableName.sort_col") and
|
||||
Session::has("crud.$tableName.sort_way") and
|
||||
Schema::hasColumn($tableName, Session::get("crud.$tableName.sort_col"))
|
||||
) {
|
||||
$models = $models->orderBy(
|
||||
Session::get("crud.$tableName.sort_col"),
|
||||
Session::get("crud.$tableName.sort_way")
|
||||
);
|
||||
}
|
||||
|
||||
$models = $this->indexQuery($models);
|
||||
/** @var \Illuminate\Pagination\AbstractPaginator */
|
||||
$models = $models->paginate(config('crud.paginate', 15));
|
||||
if ($request->ajax()) {
|
||||
return response()->json(CrudResource::collection($models));
|
||||
} else {
|
||||
$models = $models->withQueryString();
|
||||
return view('crud.index', compact('models'));
|
||||
}
|
||||
}
|
||||
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
public function show(Model $model)
|
||||
{
|
||||
return view('crud.show', compact('model'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('crud.create');
|
||||
}
|
||||
|
||||
public function store(StoreCrudModel $request)
|
||||
{
|
||||
$modelClass = static::$modelClass;
|
||||
$model = new $modelClass();
|
||||
$model->fill($request->validated());
|
||||
$this->storeModel($model);
|
||||
$model->saveOrFail();
|
||||
$model->saveRelations($request);
|
||||
$this->storedModel($model);
|
||||
return \redirect()->route(sprintf('%s.edit', $model->getTable()), $model)
|
||||
->with('success', trans(':model a bien été enregisté.', ['model' => $model->getModelName()]));
|
||||
}
|
||||
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
public function edit(Model $model)
|
||||
{
|
||||
return view('crud.edit', compact('model'));
|
||||
}
|
||||
|
||||
public function update(UpdateCrudModel $request, Model $model)
|
||||
{
|
||||
$model->fill($request->validated());
|
||||
$this->updateModel($model);
|
||||
$model->saveOrFail();
|
||||
$model->saveRelations($request);
|
||||
$this->updatedModel($model);
|
||||
return \redirect()->route(sprintf('%s.edit', $model->getTable()), $model)
|
||||
->with('success', trans(':model a bien été enregisté.', ['model' => $model->getModelName()]));
|
||||
}
|
||||
|
||||
public function destroy(Model $model)
|
||||
{
|
||||
if (
|
||||
!in_array(SoftDeletes::class, class_uses_recursive($model), true) and
|
||||
$restrict = $model->gotHasManyRelationWithRestrictOnDelete()
|
||||
) {
|
||||
return redirect()->back()
|
||||
->with('error', trans(
|
||||
':model n\'as pas pu être supprimé car il est encore associé avec des :associated',
|
||||
[
|
||||
'model' => $model->getModelName(),
|
||||
'associated' => Str::plural($restrict)
|
||||
]
|
||||
));
|
||||
}
|
||||
if ($model->delete()) {
|
||||
return \redirect()->route(sprintf('%s.index', $model->getTable()))
|
||||
->with('warning', trans(':model a bien été supprimé.', ['model' => $model->getModelName()]));
|
||||
} else {
|
||||
return redirect()->back()
|
||||
->with('error', trans(':model n\'as pas pu être supprimé', ['model' => $model->getModelName()]));
|
||||
}
|
||||
}
|
||||
|
||||
public function getModelClass()
|
||||
{
|
||||
return static::$modelClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current model class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function shareCrudModelsClassesToView(): void
|
||||
{
|
||||
$models = [];
|
||||
foreach (File::allFiles(\app_path('Http/Controllers')) as $file) {
|
||||
$class = sprintf('App\Http\Controllers\%s', \substr($file->getFilename(), 0, -4));
|
||||
if (is_subclass_of($class, CrudController::class) and $class::$modelClass) {
|
||||
$models[] = $class::$modelClass;
|
||||
}
|
||||
}
|
||||
View::share('modelsClasses', $models);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current model class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function shareModelClassToView(): void
|
||||
{
|
||||
View::share('modelClass', static::$modelClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current model class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function shareModelHasImageToView(): void
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Model $model */
|
||||
$model = static::$modelClass;
|
||||
|
||||
View::share('hasImage', (bool)collect((new $model())->getEditableProperties())->filter(function ($prop) {
|
||||
return $prop['type']->equals(CrudType::image());
|
||||
})->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current model table
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function shareModelTableToView(): void
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Model $model */
|
||||
$model = static::$modelClass;
|
||||
|
||||
View::share('modelTable', (new $model())->getTable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current model properties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function shareModelPropsToView(): void
|
||||
{
|
||||
$model = static::$modelClass;
|
||||
View::share('props', (new $model())->getEditableProperties());
|
||||
}
|
||||
}
|
||||
10
app/Http/Controllers/FileController.php
Normal file
10
app/Http/Controllers/FileController.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FileController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
31
app/Http/Controllers/LogController.php
Normal file
31
app/Http/Controllers/LogController.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Log;
|
||||
use Kwaadpepper\CrudPolicies\Http\Requests\CrudIndexRequest;
|
||||
use Kwaadpepper\CrudPolicies\Traits\CrudController;
|
||||
|
||||
class LogController extends Controller
|
||||
{
|
||||
use CrudController {
|
||||
index as crudIndex;
|
||||
}
|
||||
|
||||
/** @var Log */
|
||||
public static $modelClass = Log::class;
|
||||
|
||||
public static $layout = 'layout.app';
|
||||
|
||||
public function index(CrudIndexRequest $request)
|
||||
{
|
||||
/** @var \Illuminate\View\View */
|
||||
$view = $this->crudIndex($request);
|
||||
return view('logs.index', $view->getData());
|
||||
}
|
||||
|
||||
public function storeModel(Log &$log)
|
||||
{
|
||||
$log->parent()->associate(request()->site);
|
||||
}
|
||||
}
|
||||
16
app/Http/Controllers/ProjectController.php
Normal file
16
app/Http/Controllers/ProjectController.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Project;
|
||||
use Kwaadpepper\CrudPolicies\Traits\CrudController;
|
||||
|
||||
class ProjectController extends Controller
|
||||
{
|
||||
use CrudController;
|
||||
|
||||
/** @var Project */
|
||||
public static $modelClass = Project::class;
|
||||
|
||||
public static $layout = 'layout.app';
|
||||
}
|
||||
|
|
@ -3,10 +3,24 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Site;
|
||||
use Kwaadpepper\CrudPolicies\Http\Requests\CrudIndexRequest;
|
||||
use Kwaadpepper\CrudPolicies\Traits\CrudController;
|
||||
|
||||
class SiteController extends CrudController
|
||||
class SiteController extends Controller
|
||||
{
|
||||
use CrudController {
|
||||
index as crudIndex;
|
||||
}
|
||||
|
||||
/** @var Site */
|
||||
protected static $modelClass = Site::class;
|
||||
public static $modelClass = Site::class;
|
||||
|
||||
public static $layout = 'layout.app';
|
||||
|
||||
public function index(CrudIndexRequest $request)
|
||||
{
|
||||
/** @var \Illuminate\View\View */
|
||||
$view = $this->crudIndex($request);
|
||||
return view('sites.index', $view->getData());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,16 @@ namespace App\Http\Controllers;
|
|||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Kwaadpepper\CrudPolicies\Traits\CrudController;
|
||||
|
||||
class UserController extends CrudController
|
||||
class UserController extends Controller
|
||||
{
|
||||
use CrudController;
|
||||
|
||||
/** @var User */
|
||||
protected static $modelClass = User::class;
|
||||
public static $modelClass = User::class;
|
||||
|
||||
public static $layout = 'layout.app';
|
||||
|
||||
public function storedModel(Model &$model)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CrudIndexRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'search' => 'nullable|string'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Enums\CrudAction;
|
||||
use App\Enums\CrudType;
|
||||
use App\Exceptions\CrudException;
|
||||
use App\Http\Controllers\CrudController;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CrudRequest extends FormRequest
|
||||
{
|
||||
|
||||
/** @var array */
|
||||
protected $rules = [];
|
||||
|
||||
/**
|
||||
* Get rules for a specific action
|
||||
*
|
||||
* @param CrudAction $action
|
||||
* @return array
|
||||
*/
|
||||
public function getRulesForAction(CrudAction $action): array
|
||||
{
|
||||
$model = $this->getCurrentModel();
|
||||
$props = $this->getCurrentModel()::getEditableProperties();
|
||||
$propsRules = [];
|
||||
foreach ($this->getCurrentModel()::getRules() as $k => $rules) {
|
||||
$propsRules[$k] = [];
|
||||
$propIsAllowedOnUpdateAction = in_array($action, $props[$k]['actions']);
|
||||
foreach ($rules as $rule) {
|
||||
// dont copy required if prop is not allowed on update
|
||||
if (!$propIsAllowedOnUpdateAction and is_string($rule) and $rule == 'required') {
|
||||
continue;
|
||||
}
|
||||
if (!in_array($rule, $propsRules[$k])) {
|
||||
$propsRules[$k][] = $rule;
|
||||
}
|
||||
// handle password
|
||||
if (
|
||||
$props[$k]['type']->equals(CrudType::password()) and
|
||||
!$this->{$k} or (is_string($this->{$k}) and !\strlen($this->{$k}))
|
||||
) {
|
||||
$this->offsetUnset($k);
|
||||
}
|
||||
// handle boolean
|
||||
if ($props[$k]['type']->equals(CrudType::boolean())) {
|
||||
$this->merge([$k => $this->{$k} ? 1 : 0]);
|
||||
}
|
||||
// handle image
|
||||
if ($props[$k]['type']->equals(CrudType::image())) {
|
||||
$tableName = Str::singular((new $model())->getTable());
|
||||
if ($this->{$tableName}) {
|
||||
$i = array_search('required', $propsRules[$k]);
|
||||
unset($propsRules[$k][$i]);
|
||||
}
|
||||
}
|
||||
// handle belongsToMany
|
||||
if ($props[$k]['type']->equals(CrudType::belongsToMany())) {
|
||||
$propsRules["$k.*"][0] = 'exists:' .
|
||||
(new $props[$k]['belongsToMany']())->getTable() . ',id';
|
||||
if (!isset($this->{$k})) {
|
||||
$this->merge([$k => []]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $propsRules;
|
||||
}
|
||||
/**
|
||||
* Returns the first parameter that is a crud model
|
||||
*
|
||||
* @return string \Illuminate\Database\Eloquent\Model class name
|
||||
* @throws \App\Exceptions\CrudException if the request does not have a crud model parameter
|
||||
*/
|
||||
protected function getCurrentModel(): string
|
||||
{
|
||||
if (
|
||||
!is_object($this->route()->controller) or
|
||||
!$this->route()->controller instanceof CrudController
|
||||
) {
|
||||
throw new CrudException(sprintf(
|
||||
'Request `%s` needs to be bound on route that use a CrudController',
|
||||
get_class($this)
|
||||
));
|
||||
}
|
||||
return $this->route()->controller->getModelClass();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Enums\CrudAction;
|
||||
|
||||
class StoreCrudModel extends CrudRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
$model = $this->getCurrentModel();
|
||||
/** @var \App\Models\User|null $user */
|
||||
$user = auth()->user();
|
||||
$authorized = auth()->check() and $user->can('create', $model);
|
||||
if ($authorized) {
|
||||
$this->rules = $this->getRulesForAction(CrudAction::create());
|
||||
}
|
||||
return $authorized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return $this->rules;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Enums\Role;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreSite extends FormRequest
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Enums\CrudAction;
|
||||
|
||||
class UpdateCrudModel extends CrudRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
$model = $this->getCurrentModel();
|
||||
/** @var \App\Models\User|null $user */
|
||||
$user = auth()->user();
|
||||
$authorized = auth()->check() and $user->can('update', $model);
|
||||
if ($authorized) {
|
||||
$this->rules = $this->getRulesForAction(CrudAction::update());
|
||||
}
|
||||
return $authorized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return $this->rules;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CrudResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource collection into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'label' => $this->crudLabel,
|
||||
'value' => $this->crudValue
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Lib\PolicySystem;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Lib\PolicySystem\StaticRules as SR;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class RootPolicy
|
||||
{
|
||||
|
||||
protected $policy = null;
|
||||
|
||||
protected $policies = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$cls = \explode('\\', \get_called_class());
|
||||
$this->policy = \strtolower(\str_replace('Policy', '', \end($cls)));
|
||||
}
|
||||
|
||||
protected function actionPolicy(string $method, string $policy, User $user, Model $model = null)
|
||||
{
|
||||
$this->setPolicies($user, $model);
|
||||
$ctx = [$policy, $user, $model];
|
||||
|
||||
if (!$this->hasPolicy($policy)) {
|
||||
$m = __('Unhandled policy ":policy"', ['policy' => $policy]);
|
||||
Log::critical($m, $ctx);
|
||||
return $this->deny($m);
|
||||
}
|
||||
|
||||
if (!is_array($this->policies[$policy])) {
|
||||
$m = __('Policy ":policy" has to be array', ['policy' => $policy]);
|
||||
Log::critical($m, $ctx);
|
||||
return $this->deny($m);
|
||||
}
|
||||
|
||||
// Policy method exists
|
||||
if (!array_key_exists($method, $this->policies[$policy])) {
|
||||
$m = __('Unhandled policy ":policy" for action ":action"', ['policy' => $policy, 'action' => $method]);
|
||||
Log::critical($m, $ctx);
|
||||
return $this->deny($m);
|
||||
}
|
||||
|
||||
// Call policy method
|
||||
if (Sr::handle($this->policies[$policy][$method], $user, $model)) {
|
||||
return $this->allow();
|
||||
} else {
|
||||
$m = __('Policy ":policy" for action ":action" denied :onmodel', [
|
||||
'policy' => $policy,
|
||||
'action' => $method,
|
||||
'onmodel' => $model ? get_class($model) : ''
|
||||
]);
|
||||
if (config('app.policyDebug')) {
|
||||
Log::debug(sprintf("%s user => %s model => %s", $m, $user, $model), $ctx);
|
||||
}
|
||||
return $this->deny($m);
|
||||
}
|
||||
|
||||
$m = __('Unhandled policy case on resource ":method"', ['method' => $method]);
|
||||
Log::critical($m, $ctx);
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
** Do the magic calling Root policy from any policy
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
return call_user_func_array([$this, 'actionPolicy'], array_merge([$method, $this->policy], $args));
|
||||
}
|
||||
|
||||
private function hasPolicy(string $policy)
|
||||
{
|
||||
return array_key_exists($policy, $this->policies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow action for the user
|
||||
*
|
||||
* @param string|null $message
|
||||
* @return \Illuminate\Auth\Access\Response
|
||||
*/
|
||||
protected function allow(?string $message = null)
|
||||
{
|
||||
return Response::allow($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deny action for the user
|
||||
*
|
||||
* @param string|null $message
|
||||
* @param mixed $code
|
||||
* @return \Illuminate\Auth\Access\Response
|
||||
*/
|
||||
protected function deny(?string $message = null, $code = null)
|
||||
{
|
||||
if (!$message) {
|
||||
$message = __('This action is not allowed to you for this resource.');
|
||||
}
|
||||
return Response::deny($message, $code);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Lib\PolicySystem;
|
||||
|
||||
use App\Models\User;
|
||||
use Exception;
|
||||
use Closure;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Generic Policiy Static Rules
|
||||
*! Rules has to return boolean value
|
||||
*/
|
||||
abstract class StaticRules
|
||||
{
|
||||
/**
|
||||
* Make a rule closure
|
||||
*
|
||||
* @param string $rulename
|
||||
* @param mixed ...$args
|
||||
* @return Closure
|
||||
*/
|
||||
public static function make(string $rulename, ...$args)
|
||||
{
|
||||
if (!method_exists(static::class, $rulename)) {
|
||||
throw new Exception(sprintf('Unknown rule %s in Policies StaticRules', $rulename));
|
||||
}
|
||||
return function () use ($rulename, $args) {
|
||||
return call_user_func_array([static::class, $rulename], $args);
|
||||
};
|
||||
}
|
||||
|
||||
public static function and(array $ruleClosures)
|
||||
{
|
||||
return function (User $user, Model $model = null) use ($ruleClosures) {
|
||||
$nbRules = count($ruleClosures);
|
||||
$out = true;
|
||||
$i = 0;
|
||||
do {
|
||||
if (!($out = (self::handle($ruleClosures[$i++], $user, $model) && $out))) {
|
||||
break;
|
||||
}
|
||||
} while ($i < $nbRules);
|
||||
return $out;
|
||||
};
|
||||
}
|
||||
|
||||
public static function or(array $ruleClosures)
|
||||
{
|
||||
return function (User $user, Model $model = null) use ($ruleClosures) {
|
||||
$nbRules = count($ruleClosures);
|
||||
$out = false;
|
||||
$i = 0;
|
||||
do {
|
||||
if ($out = (self::handle($ruleClosures[$i++], $user, $model) || $out)) {
|
||||
break;
|
||||
}
|
||||
} while ($i < $nbRules);
|
||||
return $out;
|
||||
};
|
||||
}
|
||||
|
||||
public static function handle($rule, User $user, Model $model = null)
|
||||
{
|
||||
if (is_array($rule)) {
|
||||
$nbRule = count($rule);
|
||||
$out = false;
|
||||
$i = 0;
|
||||
while ($i < $nbRule) {
|
||||
if ($out = self::handle($rule[$i++], $user, $model)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
if (!is_callable($rule)) {
|
||||
throw new Exception('Rule has to ba callable.');
|
||||
}
|
||||
return (bool)$rule($user, $model);
|
||||
}
|
||||
|
||||
protected static function anyone()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
11
app/Models/File.php
Normal file
11
app/Models/File.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class File extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
63
app/Models/Log.php
Normal file
63
app/Models/Log.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Kwaadpepper\CrudPolicies\Enums\CrudAction;
|
||||
use Kwaadpepper\CrudPolicies\Enums\CrudType;
|
||||
use Kwaadpepper\CrudPolicies\Traits\IsCrudModel;
|
||||
|
||||
class Log extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use IsCrudModel;
|
||||
|
||||
protected $crudLabelColumn = 'id';
|
||||
|
||||
protected $crudValueColumn = 'id';
|
||||
|
||||
protected $fillable = ['entry'];
|
||||
|
||||
public function __construct($attributes = [])
|
||||
{
|
||||
self::$editableProperties = [
|
||||
'id' => [
|
||||
'label' => trans('ID'),
|
||||
'type' => CrudType::unsignedint(),
|
||||
'actions' => [
|
||||
CrudAction::viewAny(),
|
||||
CrudAction::view()
|
||||
]
|
||||
],
|
||||
'entry' => [
|
||||
'label' => trans('Entrée'),
|
||||
'type' => CrudType::text(),
|
||||
'required' => true,
|
||||
'nullable' => false,
|
||||
'actions' => [
|
||||
CrudAction::viewAny(),
|
||||
CrudAction::view(),
|
||||
CrudAction::create(),
|
||||
CrudAction::update(),
|
||||
]
|
||||
]
|
||||
];
|
||||
parent::__construct($attributes);
|
||||
}
|
||||
|
||||
public function parent()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public function parentSite()
|
||||
{
|
||||
return $this->morphTo('parent', 'site');
|
||||
}
|
||||
|
||||
public function parentProject()
|
||||
{
|
||||
return $this->morphTo('parent', 'project');
|
||||
}
|
||||
}
|
||||
|
|
@ -2,14 +2,10 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Events\NotifySubscriptions;
|
||||
use App\Events\NotifyTicketCreator;
|
||||
use App\Jobs\SendTicketMentionMail;
|
||||
use App\Mail\TicketMention;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
|
||||
class Message extends Model
|
||||
|
|
|
|||
134
app/Models/Project.php
Normal file
134
app/Models/Project.php
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Kwaadpepper\CrudPolicies\Enums\CrudAction;
|
||||
use Kwaadpepper\CrudPolicies\Enums\CrudType;
|
||||
use Kwaadpepper\CrudPolicies\Traits\IsCrudModel;
|
||||
|
||||
class Project extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use IsCrudModel;
|
||||
|
||||
protected $crudLabelColumn = 'name';
|
||||
|
||||
protected $crudValueColumn = 'id';
|
||||
|
||||
protected $fillable = ['name'];
|
||||
|
||||
public function __construct($attributes = [])
|
||||
{
|
||||
self::$editableProperties = [
|
||||
'name' => [
|
||||
'label' => trans('Nom'),
|
||||
'type' => CrudType::string(),
|
||||
'validate' => [
|
||||
'string',
|
||||
'max:255'
|
||||
],
|
||||
'required' => true,
|
||||
'nullable' => false,
|
||||
'actions' => [
|
||||
CrudAction::viewAny(),
|
||||
CrudAction::view(),
|
||||
CrudAction::create(),
|
||||
CrudAction::update(),
|
||||
]
|
||||
],
|
||||
'status' => [
|
||||
'label' => trans('État'),
|
||||
'type' => CrudType::string(),
|
||||
'validate' => [
|
||||
'string',
|
||||
'max:255'
|
||||
],
|
||||
'required' => true,
|
||||
'nullable' => false,
|
||||
'actions' => [
|
||||
CrudAction::viewAny(),
|
||||
CrudAction::view(),
|
||||
CrudAction::create(),
|
||||
CrudAction::update(),
|
||||
]
|
||||
],
|
||||
'description' => [
|
||||
'label' => trans('Description'),
|
||||
'type' => CrudType::text(),
|
||||
'validate' => [
|
||||
'string'
|
||||
],
|
||||
'required' => true,
|
||||
'nullable' => false,
|
||||
'actions' => [
|
||||
CrudAction::view(),
|
||||
CrudAction::create(),
|
||||
CrudAction::update(),
|
||||
]
|
||||
],
|
||||
'todo' => [
|
||||
'label' => trans('À Faire'),
|
||||
'type' => CrudType::text(),
|
||||
'validate' => [
|
||||
'string'
|
||||
],
|
||||
'required' => false,
|
||||
'nullable' => true,
|
||||
'actions' => [
|
||||
CrudAction::view(),
|
||||
CrudAction::create(),
|
||||
CrudAction::update(),
|
||||
]
|
||||
],
|
||||
'sites' => [
|
||||
'label' => trans('Sites'),
|
||||
'type' => CrudType::belongsToMany(),
|
||||
'belongsToMany' => Site::class,
|
||||
'belongsToManyLabel' => 'name',
|
||||
'nullable' => true,
|
||||
'readonly' => function () {
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
return !$user->isAdmin();
|
||||
},
|
||||
'actions' => [
|
||||
CrudAction::viewAny(),
|
||||
CrudAction::view(),
|
||||
CrudAction::create(),
|
||||
CrudAction::update(),
|
||||
]
|
||||
],
|
||||
'logs' => [
|
||||
'label' => trans('Journaux'),
|
||||
'type' => CrudType::belongsToMany(),
|
||||
'belongsToMany' => Log::class,
|
||||
'belongsToManyLabel' => 'id',
|
||||
'nullable' => true,
|
||||
'readonly' => function () {
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
return !$user->isAdmin();
|
||||
},
|
||||
'actions' => [
|
||||
CrudAction::viewAny(),
|
||||
CrudAction::view(),
|
||||
CrudAction::create(),
|
||||
CrudAction::update(),
|
||||
]
|
||||
]
|
||||
];
|
||||
parent::__construct($attributes);
|
||||
}
|
||||
|
||||
public function logs()
|
||||
{
|
||||
return $this->morphMany(Log::class, 'parent');
|
||||
}
|
||||
|
||||
public function files()
|
||||
{
|
||||
return $this->morphMany(File::class, 'parent');
|
||||
}
|
||||
}
|
||||
10
app/Models/ProjetSite.php
Normal file
10
app/Models/ProjetSite.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
class ProjetSite extends Pivot
|
||||
{
|
||||
//
|
||||
}
|
||||
|
|
@ -2,15 +2,14 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\CrudAction;
|
||||
use App\Enums\CrudType;
|
||||
use App\Enums\Role;
|
||||
use App\Traits\IsCrudModel;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
use Kwaadpepper\CrudPolicies\Enums\CrudAction;
|
||||
use Kwaadpepper\CrudPolicies\Enums\CrudType;
|
||||
use Kwaadpepper\CrudPolicies\Traits\IsCrudModel;
|
||||
|
||||
class Site extends Model
|
||||
{
|
||||
|
|
@ -52,7 +51,7 @@ class Site extends Model
|
|||
'readonly' => function () {
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
return $user->isAdmin();
|
||||
return !$user->isAdmin();
|
||||
},
|
||||
'actions' => [
|
||||
CrudAction::viewAny(),
|
||||
|
|
@ -60,6 +59,23 @@ class Site extends Model
|
|||
CrudAction::create(),
|
||||
CrudAction::update(),
|
||||
]
|
||||
],
|
||||
'logs' => [
|
||||
'label' => trans('Journaux'),
|
||||
'type' => CrudType::belongsToMany(),
|
||||
'belongsToMany' => Log::class,
|
||||
'belongsToManyLabel' => 'name',
|
||||
'nullable' => true,
|
||||
'readonly' => function () {
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
return !$user->isAdmin();
|
||||
},
|
||||
'actions' => [
|
||||
CrudAction::view(),
|
||||
CrudAction::create(),
|
||||
CrudAction::update(),
|
||||
]
|
||||
]
|
||||
];
|
||||
parent::__construct($attributes);
|
||||
|
|
@ -101,6 +117,16 @@ class Site extends Model
|
|||
return $this->hasMany(Ticket::class, 'site_id');
|
||||
}
|
||||
|
||||
public function logs()
|
||||
{
|
||||
return $this->morphMany(Log::class, 'parent');
|
||||
}
|
||||
|
||||
public function files()
|
||||
{
|
||||
return $this->morphMany(File::class, 'parent');
|
||||
}
|
||||
|
||||
public function getSlugNameAttribute()
|
||||
{
|
||||
return Str::slug($this->name);
|
||||
|
|
|
|||
10
app/Models/SiteFile.php
Normal file
10
app/Models/SiteFile.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
class SiteFile extends Pivot
|
||||
{
|
||||
//
|
||||
}
|
||||
|
|
@ -2,17 +2,17 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\CrudAction;
|
||||
use App\Enums\CrudType;
|
||||
use App\Enums\Role;
|
||||
use App\Jobs\SendUserCreatedEmail;
|
||||
use App\Traits\IsCrudModel;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
use Kwaadpepper\CrudPolicies\Enums\CrudAction;
|
||||
use Kwaadpepper\CrudPolicies\Enums\CrudType;
|
||||
use Kwaadpepper\CrudPolicies\Traits\IsCrudModel;
|
||||
use Kwaadpepper\Enum\Traits\CastsEnums;
|
||||
|
||||
class User extends Authenticatable
|
||||
|
|
@ -132,7 +132,7 @@ class User extends Authenticatable
|
|||
'readonly' => function () {
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
return $user->isAdmin();
|
||||
return !$user->isAdmin();
|
||||
},
|
||||
'actions' => [
|
||||
CrudAction::viewAny(),
|
||||
|
|
|
|||
|
|
@ -3,14 +3,15 @@
|
|||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Lib\PolicySystem\RootPolicy;
|
||||
use App\Lib\PolicySystem\StaticRules as Sr;
|
||||
use App\Policies\Rules\UserStaticRules as USR;
|
||||
use App\Policies\Rules\UserRoleRules as URR;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Kwaadpepper\CrudPolicies\Policies\RootPolicy;
|
||||
|
||||
class AppPolicies extends RootPolicy
|
||||
class FilePolicy extends RootPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Init policies on call
|
||||
*
|
||||
|
|
@ -18,26 +19,20 @@ class AppPolicies extends RootPolicy
|
|||
* @param Model $model
|
||||
* @return void
|
||||
*/
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
|
||||
public function setPolicies(User $user, Model $model = null)
|
||||
{
|
||||
/**
|
||||
* This first rule to return true in a policy action authorises the action
|
||||
*/
|
||||
$this->policies = [
|
||||
'site' => [
|
||||
'file' => [
|
||||
'viewAny' => URR::make('userIsAdmin', $user),
|
||||
'view' => URR::make('userIsAdmin', $user),
|
||||
'update' => URR::make('userIsAdmin', $user),
|
||||
'create' => URR::make('userIsAdmin', $user),
|
||||
'delete' => URR::make('userIsAdmin', $user)
|
||||
],
|
||||
'user' => [
|
||||
'viewAny' => URR::make('userIsAdmin', $user),
|
||||
'view' => URR::make('userIsAdmin', $user),
|
||||
'update' => URR::make('userIsAdmin', $user),
|
||||
'create' => URR::make('userIsAdmin', $user),
|
||||
'delete' => URR::make('userIsAdmin', $user)
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
38
app/Policies/LogPolicy.php
Normal file
38
app/Policies/LogPolicy.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserRoleRules as URR;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Kwaadpepper\CrudPolicies\Policies\RootPolicy;
|
||||
|
||||
class LogPolicy extends RootPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Init policies on call
|
||||
*
|
||||
* @param User $user
|
||||
* @param Model $model
|
||||
* @return void
|
||||
*/
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
|
||||
public function setPolicies(User $user, Model $model = null)
|
||||
{
|
||||
/**
|
||||
* This first rule to return true in a policy action authorises the action
|
||||
*/
|
||||
$this->policies = [
|
||||
'log' => [
|
||||
'viewAny' => URR::make('userIsAdmin', $user),
|
||||
'view' => URR::make('userIsAdmin', $user),
|
||||
'update' => URR::make('userIsAdmin', $user),
|
||||
'create' => URR::make('userIsAdmin', $user),
|
||||
'delete' => URR::make('userIsAdmin', $user)
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
38
app/Policies/ProjectPolicy.php
Normal file
38
app/Policies/ProjectPolicy.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserRoleRules as URR;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Kwaadpepper\CrudPolicies\Policies\RootPolicy;
|
||||
|
||||
class ProjectPolicy extends RootPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Init policies on call
|
||||
*
|
||||
* @param User $user
|
||||
* @param Model $model
|
||||
* @return void
|
||||
*/
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
|
||||
public function setPolicies(User $user, Model $model = null)
|
||||
{
|
||||
/**
|
||||
* This first rule to return true in a policy action authorises the action
|
||||
*/
|
||||
$this->policies = [
|
||||
'project' => [
|
||||
'viewAny' => URR::make('userIsAdmin', $user),
|
||||
'view' => URR::make('userIsAdmin', $user),
|
||||
'update' => URR::make('userIsAdmin', $user),
|
||||
'create' => URR::make('userIsAdmin', $user),
|
||||
'delete' => URR::make('userIsAdmin', $user)
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
20
app/Policies/Rules/SiteStaticRules.php
Normal file
20
app/Policies/Rules/SiteStaticRules.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies\Rules;
|
||||
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
use Kwaadpepper\CrudPolicies\Policies\Rules\StaticRules;
|
||||
|
||||
/**
|
||||
* Userlevel Policiy Static Rules
|
||||
*! Rules has to return boolean value
|
||||
*/
|
||||
abstract class SiteStaticRules extends StaticRules
|
||||
{
|
||||
|
||||
protected static function userSitesHasTicket(User $user, Ticket $ticket)
|
||||
{
|
||||
return $user->sites->contains($ticket->site_id);
|
||||
}
|
||||
}
|
||||
20
app/Policies/Rules/TicketStaticRules.php
Normal file
20
app/Policies/Rules/TicketStaticRules.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies\Rules;
|
||||
|
||||
use App\Enums\TicketStatus;
|
||||
use App\Models\Ticket;
|
||||
use Kwaadpepper\CrudPolicies\Policies\Rules\StaticRules;
|
||||
|
||||
/**
|
||||
* Userlevel Policiy Static Rules
|
||||
*! Rules has to return boolean value
|
||||
*/
|
||||
abstract class TicketStaticRules extends StaticRules
|
||||
{
|
||||
|
||||
protected static function ticketIsNotArchived(Ticket $ticket)
|
||||
{
|
||||
return !$ticket->status->equals(TicketStatus::archived());
|
||||
}
|
||||
}
|
||||
|
|
@ -2,9 +2,8 @@
|
|||
|
||||
namespace App\Policies\Rules;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Models\User;
|
||||
use App\Lib\PolicySystem\StaticRules;
|
||||
use Kwaadpepper\CrudPolicies\Policies\Rules\StaticRules;
|
||||
|
||||
/**
|
||||
* Userlevel Policiy Static Rules
|
||||
|
|
@ -17,4 +16,14 @@ abstract class UserRoleRules extends StaticRules
|
|||
{
|
||||
return $user->isAdmin();
|
||||
}
|
||||
|
||||
protected static function allowEveryOne()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static function denyEveryOne()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies\Rules;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Lib\PolicySystem\StaticRules;
|
||||
|
||||
/**
|
||||
* Userlevel Policiy Static Rules
|
||||
*! Rules has to return boolean value
|
||||
*/
|
||||
abstract class UserStaticRules extends StaticRules
|
||||
{
|
||||
protected static function usersAreTheSame(User $user, User $userToCheck)
|
||||
{
|
||||
return ($user->id == $userToCheck->id) != 0;
|
||||
}
|
||||
|
||||
protected static function usersAreNotTheSame(User $user, User $userToCheck)
|
||||
{
|
||||
return !self::usersAreTheSame($user, $userToCheck);
|
||||
}
|
||||
|
||||
protected static function everyOne()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static function noOne()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,11 +2,37 @@
|
|||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserRoleRules as URR;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Kwaadpepper\CrudPolicies\Policies\RootPolicy;
|
||||
|
||||
class SitePolicy extends AppPolicies
|
||||
class SitePolicy extends RootPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
// Handle delete has tickets
|
||||
/**
|
||||
* Init policies on call
|
||||
*
|
||||
* @param User $user
|
||||
* @param Model $model
|
||||
* @return void
|
||||
*/
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
|
||||
public function setPolicies(User $user, Model $model = null)
|
||||
{
|
||||
/**
|
||||
* This first rule to return true in a policy action authorises the action
|
||||
*/
|
||||
$this->policies = [
|
||||
'site' => [
|
||||
'viewAny' => URR::make('userIsAdmin', $user),
|
||||
'view' => URR::make('userIsAdmin', $user),
|
||||
'update' => URR::make('userIsAdmin', $user),
|
||||
'create' => URR::make('userIsAdmin', $user),
|
||||
'delete' => URR::make('userIsAdmin', $user)
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,129 +2,60 @@
|
|||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Enums\TicketStatus;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\SiteStaticRules as SSR;
|
||||
use App\Policies\Rules\TicketStaticRules;
|
||||
use App\Policies\Rules\UserRoleRules as URR;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Kwaadpepper\CrudPolicies\Policies\RootPolicy;
|
||||
use Kwaadpepper\CrudPolicies\Policies\Rules\StaticRules;
|
||||
|
||||
class TicketPolicy
|
||||
class TicketPolicy extends RootPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
* Init policies on call
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return mixed
|
||||
* @param User $user
|
||||
* @param Model $model
|
||||
* @return void
|
||||
*/
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
|
||||
public function viewAny(User $user)
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
|
||||
public function setPolicies(User $user, Model $model = null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\Ticket $ticket
|
||||
* @return mixed
|
||||
*/
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
|
||||
public function view(User $user, Ticket $ticket)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return mixed
|
||||
*/
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
|
||||
public function create(User $user)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\Ticket $ticket
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(User $user, Ticket $ticket)
|
||||
{
|
||||
return $user->isAdmin() or $user->sites->contains($ticket->site_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\Ticket $ticket
|
||||
* @return mixed
|
||||
*/
|
||||
//phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
|
||||
public function delete(User $user, Ticket $ticket)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\Ticket $ticket
|
||||
* @return mixed
|
||||
*/
|
||||
public function restore(User $user, Ticket $ticket)
|
||||
{
|
||||
return $user->isAdmin() or $user->sites->contains($ticket->site_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\Ticket $ticket
|
||||
* @return mixed
|
||||
*/
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
|
||||
public function forceDelete(User $user, Ticket $ticket)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function changeStatus(User $user)
|
||||
{
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
return $user->isAdmin();
|
||||
}
|
||||
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
public function suscribeToTicket(User $user, Ticket $ticket)
|
||||
{
|
||||
return !$ticket->status->equals(TicketStatus::archived());
|
||||
}
|
||||
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
public function createMessage(User $user, Ticket $ticket)
|
||||
{
|
||||
//can create if
|
||||
//role == 1
|
||||
// OR site_id IN user->sites
|
||||
|
||||
if (!($user->isAdmin() or $user->sites->contains($ticket->site_id))) {
|
||||
return Response::deny(trans('Vous ne pouvez modifier un ticket qui ne vous appartient pas.'));
|
||||
}
|
||||
return $ticket->status->equals(TicketStatus::archived()) ?
|
||||
Response::deny(trans('Vous ne pouvez ajouter un message à un ticket qui est archivé')) : Response::allow();
|
||||
/**
|
||||
* This first rule to return true in a policy action authorises the action
|
||||
*/
|
||||
$this->policies = [
|
||||
'ticket' => [
|
||||
'viewAny' => URR::make('allowEveryOne'),
|
||||
'view' => URR::make('allowEveryOne'),
|
||||
'update' => StaticRules::or([
|
||||
URR::make('userIsAdmin', $user),
|
||||
SSR::make('userSitesHasTicket', $user, $model)
|
||||
]),
|
||||
'changeStatus' => URR::make('userIsAdmin', $user),
|
||||
'create' => URR::make('userIsAdmin', $user),
|
||||
'delete' => URR::make('denyEveryOne'),
|
||||
'forceDelete' => URR::make('denyEveryOne'),
|
||||
'restore' => StaticRules::or([
|
||||
URR::make('userIsAdmin', $user),
|
||||
SSR::make('userSitesHasTicket', $user, $model)
|
||||
]),
|
||||
'suscribeToTicket' => TicketStaticRules::make('ticketIsNotArchived', $model),
|
||||
'createMessage' => StaticRules::or([
|
||||
URR::make('userIsAdmin', $user),
|
||||
StaticRules::and([
|
||||
TicketStaticRules::make('ticketIsNotArchived', $model),
|
||||
SSR::make('userSitesHasTicket', $user, $model)
|
||||
])
|
||||
])
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,37 @@
|
|||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserRoleRules as URR;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Kwaadpepper\CrudPolicies\Policies\RootPolicy;
|
||||
|
||||
class UserPolicy extends AppPolicies
|
||||
class UserPolicy extends RootPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Init policies on call
|
||||
*
|
||||
* @param User $user
|
||||
* @param Model $model
|
||||
* @return void
|
||||
*/
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
|
||||
public function setPolicies(User $user, Model $model = null)
|
||||
{
|
||||
/**
|
||||
* This first rule to return true in a policy action authorises the action
|
||||
*/
|
||||
$this->policies = [
|
||||
'user' => [
|
||||
'viewAny' => URR::make('userIsAdmin', $user),
|
||||
'view' => URR::make('userIsAdmin', $user),
|
||||
'update' => URR::make('userIsAdmin', $user),
|
||||
'create' => URR::make('userIsAdmin', $user),
|
||||
'delete' => URR::make('userIsAdmin', $user)
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\File;
|
||||
use App\Models\Log;
|
||||
use App\Models\Site;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
|
|
@ -41,6 +43,8 @@ class RouteServiceProvider extends ServiceProvider
|
|||
->namespace($this->namespace)
|
||||
->group(base_path('routes/web.php'));
|
||||
});
|
||||
Route::model('file', File::class);
|
||||
Route::model('log', Log::class);
|
||||
Route::model('user', User::class);
|
||||
Route::model('site', Site::class);
|
||||
Route::bind('ticket', function ($value) {
|
||||
|
|
|
|||
|
|
@ -1,532 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Enums\CrudAction;
|
||||
use App\Enums\CrudType;
|
||||
use App\Exceptions\CrudException;
|
||||
use App\Http\Requests\CrudRequest;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Kwaadpepper\Enum\BaseEnum;
|
||||
|
||||
trait IsCrudModel
|
||||
{
|
||||
|
||||
protected static $editableProperties = [];
|
||||
|
||||
private static $schemaCrud = [
|
||||
'label' => null,
|
||||
'placeholder' => '',
|
||||
'type' => null,
|
||||
'enum' => null,
|
||||
'nullable' => false,
|
||||
'readonly' => false,
|
||||
'disabled' => false,
|
||||
'required' => false,
|
||||
'validate' => [],
|
||||
'rules' => [],
|
||||
'actions' => [],
|
||||
'belongsTo' => null,
|
||||
'belongsToMany' => null,
|
||||
'getAttribute' => null,
|
||||
'setAttribute' => null
|
||||
];
|
||||
|
||||
// OVERLOAD MODEL FUNCTION
|
||||
public function __get($key)
|
||||
{
|
||||
if (
|
||||
isset(static::$editableProperties[$key]['getAttribute']) and
|
||||
is_callable(static::$editableProperties[$key]['getAttribute'])
|
||||
) {
|
||||
return static::$editableProperties[$key]['getAttribute']($this);
|
||||
}
|
||||
return parent::__get($key);
|
||||
}
|
||||
|
||||
// OVERLOAD MODEL FUNCTION
|
||||
public function __set($key, $value)
|
||||
{
|
||||
if (
|
||||
isset($this::$editableProperties[$key]['setAttribute']) and
|
||||
is_callable($this::$editableProperties[$key]['setAttribute'])
|
||||
) {
|
||||
return $this::$editableProperties[$key]['setAttribute']($this, $value);
|
||||
}
|
||||
return parent::__set($key, $value);
|
||||
}
|
||||
|
||||
// OVERLOAD MODEL FUNCTION
|
||||
public function fill(array $attributes)
|
||||
{
|
||||
parent::fill($attributes);
|
||||
foreach ($attributes as $k => $attribute) {
|
||||
if (
|
||||
isset(static::$editableProperties[$k]['setAttribute']) and
|
||||
is_callable(static::$editableProperties[$k]['setAttribute'])
|
||||
) {
|
||||
$this->{$k} = $attribute;
|
||||
}
|
||||
if (\is_object($this->{$k}) and \get_class($this->{$k}) === UploadedFile::class) {
|
||||
$this->moveUploadedFile($k, $this->{$k});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function saveRelations(CrudRequest $request)
|
||||
{
|
||||
$validated = $request->validated();
|
||||
$props = self::getEditableProperties();
|
||||
foreach ($props as $k => $prop) {
|
||||
if ($prop['belongsToMany'] and \is_array($validated[$k])) {
|
||||
$this->{$k}()->sync($validated[$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Has this model Has many relations with delete restrict ?
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function gotHasManyRelationWithRestrictOnDelete()
|
||||
{
|
||||
$sm = DB::getDoctrineSchemaManager();
|
||||
foreach (self::getRelationships() as $relation => $type) {
|
||||
if ($type[0] === 'HasMany') {
|
||||
$table = (new $type[1]())->getTable();
|
||||
/** @var \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey */
|
||||
foreach ($sm->listTableForeignKeys($table) as $foreignKey) {
|
||||
// /vendor/doctrine/dbal/src/Schema/ForeignKeyConstraint.php onEvent()
|
||||
if ($foreignKey->onDelete() === 'CASCADE') {
|
||||
// allow only CASCADE action, otherwise it would break the app
|
||||
continue;
|
||||
}
|
||||
return class_basename($type[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the crud label
|
||||
*/
|
||||
public function getCrudLabelAttribute()
|
||||
{
|
||||
return $this->{$this->crudLabelColumn};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the crud value
|
||||
*/
|
||||
public function getCrudValueAttribute()
|
||||
{
|
||||
if (is_null($this->crudValueColumn)) {
|
||||
throw new CrudException(sprintf(
|
||||
'[\'belongsTo\'] model `%s` must have `crudValueColumn` property',
|
||||
get_class($this),
|
||||
CrudAction::class
|
||||
));
|
||||
}
|
||||
return $this->{$this->crudValueColumn};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the crud label column
|
||||
*/
|
||||
public function getCrudLabelColumnAttribute()
|
||||
{
|
||||
if (is_null($this->crudLabelColumn)) {
|
||||
throw new CrudException(sprintf(
|
||||
'[\'belongsTo\'] model `%s` must have `crudLabelColumn` property',
|
||||
get_class($this),
|
||||
CrudAction::class
|
||||
));
|
||||
}
|
||||
return $this->crudLabelColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the crud value column
|
||||
*/
|
||||
public function getCrudValueColumnAttribute()
|
||||
{
|
||||
return $this->crudValueColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the model validation rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getRules(): array
|
||||
{
|
||||
return collect(static::$editableProperties)->mapWithKeys(function ($item, $key) {
|
||||
$item = \array_merge(self::$schemaCrud, $item);
|
||||
$defaultRules = [];
|
||||
if (!$item['nullable'] === true) {
|
||||
$defaultRules[] = 'required';
|
||||
} elseif ($item['required'] === true) {
|
||||
$defaultRules[] = 'required';
|
||||
} elseif ($item['readonly'] === true) {
|
||||
$defaultRules[] = 'prohibited';
|
||||
}
|
||||
switch ($item['type']) {
|
||||
case CrudType::boolean():
|
||||
$defaultRules[] = 'boolean';
|
||||
break;
|
||||
case CrudType::image():
|
||||
$defaultRules[] = 'file';
|
||||
break;
|
||||
case CrudType::email():
|
||||
$defaultRules[] = 'email:rfc,dns';
|
||||
break;
|
||||
case CrudType::belongsTo():
|
||||
$defaultRules[] = 'integer';
|
||||
$defaultRules[] = 'min:0';
|
||||
break;
|
||||
case CrudType::int():
|
||||
$defaultRules[] = 'integer';
|
||||
break;
|
||||
case CrudType::belongsToMany():
|
||||
$defaultRules[] = 'array';
|
||||
break;
|
||||
case CrudType::password():
|
||||
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||||
$defaultRules[] = "regex:/^(?=.*[A-Z])(?=.*[²&~\"#'\{\(\[\-|`_\\^@\)\°=+\}¨^\$£¤%?,;.:\/!§*<>])(?=.*[0-9].*)(?=.*[a-z]).{8,}$/";
|
||||
break;
|
||||
case CrudType::text():
|
||||
case CrudType::string():
|
||||
default:
|
||||
$defaultRules[] = 'string';
|
||||
break;
|
||||
}
|
||||
return [$key => array_merge($defaultRules, $item['validate'] ?? self::$schemaCrud['validate'])];
|
||||
})->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the model Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModelName(): string
|
||||
{
|
||||
return class_basename(get_class($this));
|
||||
}
|
||||
|
||||
private function moveUploadedFile(string $propName, UploadedFile &$file): void
|
||||
{
|
||||
$this->{$propName} = $file->storePubliclyAs(
|
||||
$this->getTable(),
|
||||
$file->hashName(),
|
||||
['disk' => 'public']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Editable Properties
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getEditableProperties(): array
|
||||
{
|
||||
static::assertEditablePropertiesIsCorrect();
|
||||
return static::$editableProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert self::$editableProperties is in a correct format
|
||||
*
|
||||
* 'string' => CrudType::value()
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function assertEditablePropertiesIsCorrect(): void
|
||||
{
|
||||
if (empty(static::$editableProperties)) {
|
||||
throw new CrudException('$editableProperties must be defined in ' . __CLASS__);
|
||||
}
|
||||
foreach (static::$editableProperties as $name => &$prop) {
|
||||
if (!is_string($name)) {
|
||||
throw new CrudException(sprintf(
|
||||
'editableProperties array value must be an array given: %s',
|
||||
print_r($prop, true) // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Found
|
||||
));
|
||||
}
|
||||
if (!is_array($prop)) {
|
||||
throw new CrudException(sprintf(
|
||||
'editableProperties array value must be an array given: %s',
|
||||
print_r($prop, true) // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Found
|
||||
));
|
||||
}
|
||||
$prop = array_merge_recursive_distinct(self::$schemaCrud, $prop);
|
||||
|
||||
// Auto label
|
||||
$prop['label'] = $prop['label'] ?? ucfirst($name);
|
||||
self::assertLabelIscorrect($prop);
|
||||
self::assertPlaceholderIscorrect($prop);
|
||||
self::assertTypeIscorrect($prop);
|
||||
switch ($prop['type']) {
|
||||
// Email auto rule
|
||||
case CrudType::email():
|
||||
$prop['validate'] = is_array($prop['validate']) ? $prop['validate'] : [];
|
||||
if (!array_search('email:rfc,dns', $prop['validate'])) {
|
||||
$prop['validate'][] = 'email:rfc,dns';
|
||||
}
|
||||
break;
|
||||
case CrudType::json():
|
||||
$prop['validate'] = is_array($prop['validate']) ? $prop['validate'] : [];
|
||||
if (!array_search('json', $prop['validate'])) {
|
||||
$prop['validate'][] = 'json';
|
||||
}
|
||||
break;
|
||||
}
|
||||
self::assertNullableIscorrect($prop);
|
||||
self::assertReadonlyIscorrect($prop);
|
||||
self::assertDisabledIscorrect($prop);
|
||||
self::assertValidateIscorrect($prop);
|
||||
self::assertRulesArecorrect($prop);
|
||||
self::assertActionsArecorrect($prop);
|
||||
self::assertBelongsToIsCorrect($prop);
|
||||
self::assertEnumIscorrect($prop);
|
||||
self::assertGetAttributeIscorrect($prop);
|
||||
self::assertSetAttributeIscorrect($prop);
|
||||
self::assertBelongsToManyIsCorrect($prop);
|
||||
}
|
||||
}
|
||||
|
||||
private static function assertLabelIscorrect(array $prop): void
|
||||
{
|
||||
if (!isset($prop['label']) or !is_string($prop['label'])) {
|
||||
throw new CrudException('$editableProperties[\'label\'] array value must be a string');
|
||||
}
|
||||
}
|
||||
|
||||
private static function assertPlaceholderIscorrect(array $prop): void
|
||||
{
|
||||
if (!isset($prop['placeholder']) or !is_string($prop['placeholder'])) {
|
||||
throw new CrudException('$editableProperties[\'placeholder\'] array value must be a string');
|
||||
}
|
||||
}
|
||||
|
||||
private static function assertTypeIscorrect(array $prop): void
|
||||
{
|
||||
if (!isset($prop['type']) or !is_object($prop['type']) or get_class($prop['type']) !== CrudType::class) {
|
||||
throw new CrudException('$editableProperties[\'type\'] value must be a CrudType enum');
|
||||
}
|
||||
}
|
||||
|
||||
private static function assertNullableIscorrect(array $prop): void
|
||||
{
|
||||
if (!isset($prop['nullable']) or !is_bool($prop['nullable'])) {
|
||||
throw new CrudException('$editableProperties[\'nullable\'] array value must be a boolean');
|
||||
}
|
||||
}
|
||||
|
||||
private static function assertReadonlyIscorrect(array $prop): void
|
||||
{
|
||||
if (
|
||||
!isset($prop['readonly']) or
|
||||
(!is_bool($prop['readonly']) and !\is_callable($prop['readonly']))
|
||||
) {
|
||||
throw new CrudException('$editableProperties[\'readonly\'] array value must be a boolean or a function returnning a boolean');
|
||||
}
|
||||
}
|
||||
|
||||
private static function assertDisabledIscorrect(array $prop): void
|
||||
{
|
||||
if (!isset($prop['disabled']) or !is_bool($prop['disabled'])) {
|
||||
throw new CrudException('$editableProperties[\'disabled\'] array value must be a boolean');
|
||||
}
|
||||
}
|
||||
|
||||
private static function assertRequiredIscorrect(array $prop): void
|
||||
{
|
||||
if (!isset($prop['required']) or !is_bool($prop['required'])) {
|
||||
throw new CrudException('$editableProperties[\'required\'] array value must be a boolean');
|
||||
}
|
||||
}
|
||||
|
||||
private static function assertValidateIscorrect(array $prop): void
|
||||
{
|
||||
if (!isset($prop['validate']) or !\is_array($prop['validate'])) {
|
||||
throw new CrudException('$editableProperties[\'validate\'] array value must be an array');
|
||||
}
|
||||
}
|
||||
|
||||
private static function assertGetAttributeIscorrect(array $prop): void
|
||||
{
|
||||
if (!is_null($prop['getAttribute']) and !is_callable($prop['getAttribute'])) {
|
||||
throw new CrudException('$editableProperties[\'getAttribute\'] array value must be callable');
|
||||
}
|
||||
}
|
||||
|
||||
private static function assertSetAttributeIscorrect(array $prop): void
|
||||
{
|
||||
if (!is_null($prop['setAttribute']) and !is_callable($prop['setAttribute'])) {
|
||||
throw new CrudException('$editableProperties[\'setAttribute\'] array value must be callable');
|
||||
}
|
||||
}
|
||||
|
||||
private static function assertRulesArecorrect(array $prop): void
|
||||
{
|
||||
$allowedRules = [
|
||||
'min' => function ($v) {
|
||||
return \is_numeric($v);
|
||||
},
|
||||
'max' => function ($v) {
|
||||
return \is_numeric($v);
|
||||
},
|
||||
'step' => function ($v) {
|
||||
return \is_numeric($v);
|
||||
},
|
||||
];
|
||||
if (!isset($prop['rules']) or !\is_array($prop['rules'])) {
|
||||
throw new CrudException('$editableProperties[\'rules\'] array value must be an array');
|
||||
}
|
||||
if (count(array_diff_key($prop['rules'], $allowedRules))) {
|
||||
throw new CrudException(sprintf(
|
||||
'$editableProperties[\'rules\'] array contains unallowed rule, allowed are : %s',
|
||||
implode(',', array_keys($allowedRules))
|
||||
));
|
||||
}
|
||||
foreach ($allowedRules as $k => $f) {
|
||||
if (array_key_exists($k, $prop['rules']) and !$f($prop['rules'][$k])) {
|
||||
throw new CrudException(sprintf(
|
||||
'$editableProperties[\'rules\'] rule `%s` does not validate with value `%s`',
|
||||
$k,
|
||||
$prop['rules'][$k]
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function assertActionsArecorrect(array $prop): void
|
||||
{
|
||||
if (!isset($prop['actions']) or !\is_array($prop['actions'])) {
|
||||
throw new CrudException('$editableProperties[\'actions\'] array value must be an array');
|
||||
}
|
||||
foreach ($prop['actions'] as $action) {
|
||||
if (!is_object($action) or get_class($action) !== CrudAction::class) {
|
||||
throw new CrudException(sprintf(
|
||||
'$editableProperties[\'actions\'] array value must contain `%s` objects',
|
||||
CrudAction::class
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function assertEnumIscorrect(array $prop): void
|
||||
{
|
||||
if (
|
||||
$prop['type']->equals(CrudType::enum()) and (is_null($prop['enum']) or
|
||||
!\is_subclass_of($prop['enum'], BaseEnum::class))
|
||||
) {
|
||||
throw new CrudException(sprintf(
|
||||
'$editableProperties[\'enum\'] array value must be an enum `%s`',
|
||||
BaseEnum::class
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private static function assertBelongsToIsCorrect(array $prop): void
|
||||
{
|
||||
if (is_null($prop['belongsTo'])) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
$prop['type']->equals(CrudType::belongsTo()) and
|
||||
(!\is_string($prop['belongsTo']) or
|
||||
!\class_exists($prop['belongsTo']) or
|
||||
is_a($prop['belongsTo'], Model::class, true) or
|
||||
!in_array(IsCrudModel::class, class_uses_recursive($prop['belongsTo'])))
|
||||
) {
|
||||
throw new CrudException(sprintf(
|
||||
'$editableProperties[\'belongsTo\'] array value must be a CrudModel given: `%s`',
|
||||
$prop['belongsTo']
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private static function assertBelongsToManyIsCorrect(array $prop): void
|
||||
{
|
||||
if (is_null($prop['belongsToMany'])) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
$prop['type']->equals(CrudType::belongsToMany()) and
|
||||
(!\is_string($prop['belongsToMany']) or
|
||||
!\class_exists($prop['belongsToMany']) or
|
||||
is_a($prop['belongsToMany'], Model::class, true) or
|
||||
!in_array(IsCrudModel::class, class_uses_recursive($prop['belongsToMany'])))
|
||||
) {
|
||||
throw new CrudException(sprintf(
|
||||
'$editableProperties[\'belongsToMany\'] array value must be a CrudModel given: `%s`',
|
||||
$prop['belongsToMany']
|
||||
));
|
||||
}
|
||||
if (
|
||||
$prop['type']->equals(CrudType::belongsToMany()) and
|
||||
(!\is_string($prop['belongsToManyLabel']))
|
||||
) {
|
||||
throw new CrudException(sprintf(
|
||||
'$editableProperties[\'belongsToManyLabel\'] must be string using belongsToMany, given: `%s`',
|
||||
$prop['belongsToMany']
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get eloquent relationships
|
||||
*
|
||||
* @url https://laracasts.com/discuss/channels/eloquent/get-all-model-relationships
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function getRelationships()
|
||||
{
|
||||
$instance = new static();
|
||||
|
||||
// Get public methods declared without parameters and non inherited
|
||||
$class = get_class($instance);
|
||||
$allMethods = (new \ReflectionClass($class))->getMethods(\ReflectionMethod::IS_PUBLIC);
|
||||
$methods = array_filter(
|
||||
$allMethods,
|
||||
function ($method) use ($class) {
|
||||
return $method->class === $class
|
||||
&& !$method->getParameters() // relationships have no parameters
|
||||
&& $method->getName() !== 'getRelationships' // prevent infinite recursion
|
||||
&& $method->getName() !== 'gotHasManyRelationWithRestrictOnDelete'; // prevent infinite recursion
|
||||
}
|
||||
);
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$relations = [];
|
||||
foreach ($methods as $method) {
|
||||
try {
|
||||
$methodName = $method->getName();
|
||||
$methodReturn = $instance->$methodName();
|
||||
if (!$methodReturn instanceof Relation) {
|
||||
continue;
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = (new \ReflectionClass($methodReturn))->getShortName();
|
||||
$model = get_class($methodReturn->getRelated());
|
||||
$relations[$methodName] = [$type, $model];
|
||||
}
|
||||
|
||||
DB::rollBack();
|
||||
|
||||
return $relations;
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
"fideloper/proxy": "^4.4",
|
||||
"fruitcake/laravel-cors": "^2.0",
|
||||
"guzzlehttp/guzzle": "^7.0.1",
|
||||
"kwaadpepper/crud-policies": "^0.1.6",
|
||||
"kwaadpepper/enum": "^0.1.4",
|
||||
"laravel/framework": "^8.12",
|
||||
"laravel/tinker": "^2.5",
|
||||
|
|
|
|||
7942
composer.lock
generated
Normal file
7942
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -14,11 +14,20 @@ class RenameProjectsTableIntoSitesTable extends Migration
|
|||
public function up()
|
||||
{
|
||||
Schema::rename('projects', 'sites');
|
||||
Schema::table('project_user', function (Blueprint $table) {
|
||||
$table->dropForeign('project_user_project_id_foreign');
|
||||
$table->dropUnique(['project_id', 'user_id']);
|
||||
});
|
||||
Schema::rename('project_user', 'site_user');
|
||||
Schema::table('site_user', function (Blueprint $table) {
|
||||
$table->dropForeign('project_user_project_id_foreign');
|
||||
$table->renameColumn('project_id ', 'site_id');
|
||||
$table->foreignId('site_id')->constrained('sites');
|
||||
$table->renameColumn('project_id', 'site_id');
|
||||
$table->foreign('site_id')->references('id')->on('sites');
|
||||
$table->unique(['site_id', 'user_id']);
|
||||
});
|
||||
Schema::table('tickets', function (Blueprint $table) {
|
||||
$table->dropForeign('tickets_project_id_foreign');
|
||||
$table->renameColumn('project_id', 'site_id');
|
||||
$table->foreign('site_id')->references('id')->on('sites');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -30,11 +39,20 @@ class RenameProjectsTableIntoSitesTable extends Migration
|
|||
public function down()
|
||||
{
|
||||
Schema::rename('sites', 'projects');
|
||||
Schema::table('site_user', function (Blueprint $table) {
|
||||
$table->dropForeign('site_user_site_id_foreign');
|
||||
$table->dropUnique(['site_id', 'user_id']);
|
||||
});
|
||||
Schema::rename('site_user', 'project_user');
|
||||
Schema::table('project_user', function (Blueprint $table) {
|
||||
$table->dropForeign('site_user_site_id_foreign');
|
||||
$table->renameColumn('site_id ', 'project_id');
|
||||
$table->foreignId('project_id')->constrained('projects');
|
||||
$table->renameColumn('site_id', 'project_id');
|
||||
$table->foreign('project_id')->references('id')->on('projects');
|
||||
$table->unique(['project_id', 'user_id']);
|
||||
});
|
||||
Schema::table('tickets', function (Blueprint $table) {
|
||||
$table->dropForeign('tickets_site_id_foreign');
|
||||
$table->renameColumn('site_id', 'project_id');
|
||||
$table->foreign('project_id')->references('id')->on('projects');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateProjectsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('projects', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('status');
|
||||
$table->text('description');
|
||||
$table->text('todo')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('projects');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateProjetSiteTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('projet_site', function (Blueprint $table) {
|
||||
$table->foreignId('project_id')->constrained('projects')->cascadeOnDelete();
|
||||
$table->foreignId('site_id')->constrained('sites');
|
||||
$table->unique(['project_id', 'site_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('projet_site');
|
||||
}
|
||||
}
|
||||
33
database/migrations/2021_07_23_152810_create_logs_table.php
Normal file
33
database/migrations/2021_07_23_152810_create_logs_table.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateLogsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->text('entry');
|
||||
$table->morphs('parent'); // can be Site or Projet
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('logs');
|
||||
}
|
||||
}
|
||||
36
database/migrations/2021_07_23_153446_create_files_table.php
Normal file
36
database/migrations/2021_07_23_153446_create_files_table.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateFilesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('files', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('path');
|
||||
$table->smallInteger('type');
|
||||
$table->smallInteger('category');
|
||||
$table->morphs('parent'); // can be Site or Projet
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('files');
|
||||
}
|
||||
}
|
||||
2
public/css/app.css
vendored
2
public/css/app.css
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
public/js/app.js
vendored
2
public/js/app.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -1,9 +1,3 @@
|
|||
/*!
|
||||
* Vue.js v2.6.14
|
||||
* (c) 2014-2021 Evan You
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Lodash <https://lodash.com/>
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
1
resources/js/app.js
vendored
1
resources/js/app.js
vendored
|
|
@ -1,2 +1 @@
|
|||
require('./bootstrap');
|
||||
require('./crud');
|
||||
|
|
|
|||
31
resources/js/bootstrap.js
vendored
31
resources/js/bootstrap.js
vendored
|
|
@ -33,35 +33,4 @@ window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
|
|||
// forceTLS: true
|
||||
// });
|
||||
|
||||
window.Vue = require('vue').default;
|
||||
import vSelect from "vue-select"
|
||||
Vue.component('v-select', vSelect)
|
||||
|
||||
let vueOptions = {
|
||||
el: "#app"
|
||||
};
|
||||
|
||||
// register modules
|
||||
const modules = require.context("./modules", true, /\.js$/i);
|
||||
modules.keys().map(key => Vue.mixin(modules(key).default));
|
||||
|
||||
// Register components
|
||||
const vues = require.context("./components", true, /\.vue$/i);
|
||||
vues.keys().map(key =>
|
||||
Vue.component(
|
||||
key
|
||||
.split("/")
|
||||
.pop()
|
||||
.split(".")[0]
|
||||
.replace(/\.?([A-Z])/g, function (x, y) {
|
||||
return "-" + y.toLowerCase();
|
||||
})
|
||||
.replace(/^-/, "")
|
||||
.replace("-component", ""),
|
||||
vues(key).default
|
||||
)
|
||||
);
|
||||
|
||||
const app = new Vue(vueOptions);
|
||||
|
||||
require('fslightbox');
|
||||
|
|
|
|||
|
|
@ -1,112 +0,0 @@
|
|||
<template>
|
||||
<div>
|
||||
<v-select
|
||||
:id="name"
|
||||
ref="select"
|
||||
:loading="loading"
|
||||
v-model="value"
|
||||
:clearable="false"
|
||||
label="label"
|
||||
:options='data'
|
||||
@search="search"
|
||||
:filterable="true"
|
||||
:disabled="dReadonly||dDisabled"
|
||||
:searchable="true">
|
||||
<li slot="list-footer" class="pagination">
|
||||
<button
|
||||
@click="$event.preventDefault(); page -= 1"
|
||||
:disabled="!hasPrevPage"
|
||||
class="btn btn-sm btn-primary mt-2 mb-2 ms-2 me-2">{{ __('Précédent') }}</button>
|
||||
<button
|
||||
@click="$event.preventDefault(); page += 1"
|
||||
:disabled="!hasNextPage"
|
||||
class="btn btn-sm btn-primary mt-2 mb-2">{{ __('Suivant') }}</button>
|
||||
</li>
|
||||
</v-select>
|
||||
<input type="hidden" v-model="value.value" :name="name" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
mounted() {
|
||||
this.dDisabled = !!this.disabled
|
||||
this.dReadonly = !!this.readonly
|
||||
this.value = JSON.parse(this.dbValue)
|
||||
if(!this.value) {
|
||||
this.value = {
|
||||
label: null,
|
||||
value: null
|
||||
}
|
||||
}
|
||||
this.search(false)
|
||||
},
|
||||
props: [
|
||||
'disabled',
|
||||
'readonly',
|
||||
'name',
|
||||
'dbValue'
|
||||
],
|
||||
data() {
|
||||
return {
|
||||
dDisabled : false,
|
||||
dReadonly : false,
|
||||
value: {
|
||||
label: null,
|
||||
value: null
|
||||
},
|
||||
loading: false,
|
||||
searchText: '',
|
||||
data: [],
|
||||
page: 1,
|
||||
perPage: 15,
|
||||
hasNextPage: true,
|
||||
hasPrevPage: false
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
page() {
|
||||
if(this.page < 1) {
|
||||
this.page = 1
|
||||
}
|
||||
if(this.page > 1) {
|
||||
this.hasPrevPage = true
|
||||
} else {
|
||||
this.hasPrevPage = false
|
||||
}
|
||||
this.search()
|
||||
},
|
||||
data() {
|
||||
if(this.data.length == this.perPage) {
|
||||
this.hasNextPage = true
|
||||
} else {
|
||||
this.hasNextPage = false
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
search (search = null) {
|
||||
if(search !== false && search !== null) {
|
||||
this.searchText = search
|
||||
}
|
||||
let init = search === false ? true : false
|
||||
let route = this.route('model.index')
|
||||
route += '?page='+this.page
|
||||
route += '&s='+this.searchText
|
||||
this.loading = true
|
||||
axios.get(route)
|
||||
.then(response => {
|
||||
this.data = response.data
|
||||
if (init && this.data.length && this.value.value == null) {
|
||||
this.value = this.data[0]
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
}).then(() => {
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
@ -1,108 +0,0 @@
|
|||
<template>
|
||||
<div>
|
||||
<v-select
|
||||
:id="name"
|
||||
ref="select"
|
||||
:loading="loading"
|
||||
v-model="values"
|
||||
:clearable="true"
|
||||
label="label"
|
||||
:options='data'
|
||||
@search="search"
|
||||
multiple
|
||||
:disabled="dReadonly||dDisabled"
|
||||
:filterable="true"
|
||||
:searchable="true">
|
||||
<li slot="list-footer" class="pagination">
|
||||
<button
|
||||
@click="$event.preventDefault(); page -= 1"
|
||||
:disabled="!hasPrevPage"
|
||||
class="btn btn-sm btn-primary mt-2 mb-2 ms-2 me-2">{{ __('Précédent') }}</button>
|
||||
<button
|
||||
@click="$event.preventDefault(); page += 1"
|
||||
:disabled="!hasNextPage"
|
||||
class="btn btn-sm btn-primary mt-2 mb-2">{{ __('Suivant') }}</button>
|
||||
</li>
|
||||
</v-select>
|
||||
<input
|
||||
type="hidden"
|
||||
:name="name+'[]'"
|
||||
v-for="item in values" :key="item.value"
|
||||
:value="item.value"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
mounted() {
|
||||
this.dDisabled = !!this.disabled
|
||||
this.dReadonly = !!this.readonly
|
||||
let values = JSON.parse(this.dbValue)
|
||||
for(let k in values) {
|
||||
this.values.push(values[k])
|
||||
}
|
||||
this.search(false)
|
||||
},
|
||||
props: [
|
||||
'disabled',
|
||||
'readonly',
|
||||
'name',
|
||||
'dbValue'
|
||||
],
|
||||
data() {
|
||||
return {
|
||||
dDisabled : false,
|
||||
dReadonly : false,
|
||||
values: [],
|
||||
loading: false,
|
||||
searchText: '',
|
||||
data: [],
|
||||
page: 1,
|
||||
perPage: 15,
|
||||
hasNextPage: true,
|
||||
hasPrevPage: false
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
page() {
|
||||
if(this.page < 1) {
|
||||
this.page = 1
|
||||
}
|
||||
if(this.page > 1) {
|
||||
this.hasPrevPage = true
|
||||
} else {
|
||||
this.hasPrevPage = false
|
||||
}
|
||||
this.search()
|
||||
},
|
||||
data() {
|
||||
if(this.data.length == this.perPage) {
|
||||
this.hasNextPage = true
|
||||
} else {
|
||||
this.hasNextPage = false
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
search (search = null) {
|
||||
if(search !== false && search !== null) {
|
||||
this.searchText = search
|
||||
}
|
||||
let init = search === false ? true : false
|
||||
let route = this.route('model.index')
|
||||
route += '?page='+this.page
|
||||
route += '&s='+this.searchText
|
||||
this.loading = true
|
||||
axios.get(route)
|
||||
.then(response => {
|
||||
this.data = response.data
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
}).then(() => {
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
19
resources/js/crud.js
vendored
19
resources/js/crud.js
vendored
|
|
@ -1,19 +0,0 @@
|
|||
window.__CRUD = {
|
||||
confirmDelete: (e) => {
|
||||
let self = e.target
|
||||
e.preventDefault();
|
||||
Swal.fire({
|
||||
title: 'Confirmez',
|
||||
text: 'Voulez-vous vraiment supprimer cet élément ?',
|
||||
icon: 'question',
|
||||
confirmButtonText: 'Supprimer',
|
||||
showCancelButton: true,
|
||||
cancelButtonText: 'Annuler',
|
||||
confirmButtonColor: '#dc3545'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
self.submit()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
8
resources/js/modules/asset.js
vendored
8
resources/js/modules/asset.js
vendored
|
|
@ -1,8 +0,0 @@
|
|||
export default {
|
||||
methods: {
|
||||
asset(path) {
|
||||
return window._asset + path;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
8
resources/js/modules/route.js
vendored
8
resources/js/modules/route.js
vendored
|
|
@ -1,8 +0,0 @@
|
|||
export default {
|
||||
methods: {
|
||||
route(routeName) {
|
||||
return Object.keys(window._routes).indexOf(routeName) !== -1 ? window._routes[routeName] : null;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
41
resources/js/modules/trans.js
vendored
41
resources/js/modules/trans.js
vendored
|
|
@ -1,41 +0,0 @@
|
|||
export default {
|
||||
data() {
|
||||
return {
|
||||
locale: window._locale
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* Translate the given key.
|
||||
*/
|
||||
__(key, replace) {
|
||||
let translation, translationNotFound = true, vars;
|
||||
|
||||
try {
|
||||
translation = key.split('.').reduce((t, i) => t[i] || null, window._translations.php)
|
||||
if (translation) {
|
||||
translationNotFound = false;
|
||||
}
|
||||
} catch (e) {
|
||||
translation = key;
|
||||
}
|
||||
|
||||
if (translationNotFound) {
|
||||
translation = window._translations['json'][key] ? window._translations['json'][key] : key;
|
||||
}
|
||||
vars = translation.match(/:[0-9A-Za-z_]*/g);
|
||||
if (vars) {
|
||||
for (let match of vars) {
|
||||
try {
|
||||
translation = translation.replace(new RegExp(match, 'g'), replace[match.substr(1)]);
|
||||
} catch (e) {
|
||||
console.error('String replace failed ', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return translation
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
12
resources/sass/_crud.scss
vendored
12
resources/sass/_crud.scss
vendored
|
|
@ -1,12 +0,0 @@
|
|||
@import "vue-select/src/scss/vue-select.scss";
|
||||
|
||||
// readonly checkboxes
|
||||
select[readonly],input[type='checkbox'][readonly]{
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
//bootstrap overload
|
||||
.btn-group > form:not(:first-child) > .btn-group:not(:last-child) > .btn, .btn-group > form:not(:first-child) > .btn:last-child:not(.dropdown-toggle) {
|
||||
border-top-left-radius: 0;
|
||||
border-bottom-left-radius: 0;
|
||||
}
|
||||
1
resources/sass/app.scss
vendored
1
resources/sass/app.scss
vendored
|
|
@ -3,7 +3,6 @@
|
|||
// Fonts
|
||||
@import url('https://fonts.googleapis.com/css?family=Nunito');
|
||||
|
||||
@import 'crud';
|
||||
// Variables
|
||||
@import 'variables';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,53 +0,0 @@
|
|||
@extends('layout.app')
|
||||
|
||||
@section('title', sprintf('%s - Ajouter', Str::plural(class_basename($modelClass))))
|
||||
@section('description', sprintf('Ajouter un %s', class_basename($modelClass)))
|
||||
@section('metaIndex', 'noindex,nofollow')
|
||||
|
||||
@section('content')
|
||||
<div class="container container-xxl">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
@include('modules.flashMessage')
|
||||
<div class="card-header">
|
||||
@can('viewAny', $modelClass)
|
||||
<a href="{{route("$modelTable.index")}}">{{ trans(Str::plural(class_basename($modelClass))) }}</a> - {{ __('Ajouter') }}
|
||||
@else
|
||||
{{ Str::plural(class_basename($modelClass)) }} - {{ __('Ajouter') }}
|
||||
@endcan
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="{{ route("$modelTable.store") }}" method="POST" @if($hasImage) enctype="multipart/form-data" @endif>
|
||||
@csrf
|
||||
<table class="table table-sm table-bordered border-primary align-middle table-striped text-center">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
<th scope="col" class="w-25">{{ __('Propriété') }}</th>
|
||||
<th scope="col" class="w-75">{{ __('Valeur') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($modelClass::getEditableProperties() as $fieldName => $prop)
|
||||
@php
|
||||
// create form cannot accept readonly field
|
||||
$prop['readonly'] = false;
|
||||
@endphp
|
||||
@if(in_array(CrudAction::create(), $prop['actions']))
|
||||
<tr>
|
||||
@include('crud.formfield')
|
||||
</tr>
|
||||
@endif
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="col text-center">
|
||||
<button class="btn btn-info" type="submit">{{ __('Créer') }}</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
@extends('layout.app')
|
||||
|
||||
@section('title', sprintf('%s - Editer', trans(Str::plural(class_basename($modelClass)))))
|
||||
@section('description', sprintf('Editer un %s', trans(class_basename($modelClass))))
|
||||
@section('metaIndex', 'noindex,nofollow')
|
||||
|
||||
@section('content')
|
||||
<div class="container container-xxl">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
@include('modules.flashMessage')
|
||||
<div class="card-header">
|
||||
@can('viewAny', $modelClass)
|
||||
<a href="{{route("$modelTable.index")}}">{{ trans(Str::plural(class_basename($modelClass))) }}</a> - {{ __('Editer') }}
|
||||
@else
|
||||
{{ trans(Str::plural(class_basename($modelClass))) }} - {{ __('Editer') }}
|
||||
@endcan
|
||||
<div class="btn-group float-end" role="group" aria-label="{{ __('Actions') }}">
|
||||
@can('view', $model)
|
||||
<a href="{{route("$modelTable.show", $model)}}" class="btn btn-primary ">{{ __('Voir') }}</a>
|
||||
@endcan
|
||||
@can('delete', $model)
|
||||
<form action="{{route("$modelTable.destroy", $model)}}" method="POST" onsubmit="__CRUD.confirmDelete(event)">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="btn btn-danger">{{ __('Supprimer') }}</button>
|
||||
</form>
|
||||
@endcan
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="{{ route("$modelTable.update", $model) }}" method="POST" @if($hasImage) enctype="multipart/form-data" @endif>
|
||||
@method('put')
|
||||
@csrf
|
||||
<table class="table table-sm table-bordered border-primary align-middle table-striped text-center">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
<th scope="col" class="w-25">{{ __('Propriété') }}</th>
|
||||
<th scope="col" class="w-75">{{ __('Valeur') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($modelClass::getEditableProperties() as $fieldName => $prop)
|
||||
@if(in_array(CrudAction::update(), $prop['actions']))
|
||||
<tr>
|
||||
@include('crud.formfield')
|
||||
</tr>
|
||||
@endif
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="col text-center">
|
||||
<button class="btn btn-info" type="submit">{{ __('Modifier') }}</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
@php
|
||||
$readonly = is_callable($prop['readonly']) ? $prop['readonly']() : $prop['readonly'];
|
||||
@endphp
|
||||
@switch($prop['type'])
|
||||
@case(CrudType::password())
|
||||
@include('crud.formfields.password')
|
||||
@break
|
||||
@case(CrudType::boolean())
|
||||
@include('crud.formfields.boolean')
|
||||
@break
|
||||
@case(CrudType::int())
|
||||
@include('crud.formfields.int')
|
||||
@break
|
||||
@case(CrudType::float())
|
||||
@include('crud.formfields.float')
|
||||
@break
|
||||
@case(CrudType::email())
|
||||
@include('crud.formfields.email')
|
||||
@break
|
||||
@case(CrudType::text())
|
||||
@include('crud.formfields.text')
|
||||
@break
|
||||
@case(CrudType::json())
|
||||
@include('crud.formfields.json')
|
||||
@break
|
||||
@case(CrudType::image())
|
||||
@include('crud.formfields.image')
|
||||
@break
|
||||
@case(CrudType::enum())
|
||||
@include('crud.formfields.enum')
|
||||
@break
|
||||
@case(CrudType::belongsTo())
|
||||
@include('crud.formfields.belongsTo')
|
||||
@break
|
||||
@case(CrudType::belongsToMany())
|
||||
@include('crud.formfields.belongsToMany')
|
||||
@break
|
||||
@case(CrudType::string())
|
||||
@default
|
||||
@include('crud.formfields.string')
|
||||
@endswitch
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<td>
|
||||
<label for="{{ $fieldName }}" class="form-label">{{ $prop['label'] }}</label>
|
||||
</td>
|
||||
<td>
|
||||
<div class="mb-3">
|
||||
<textarea id="{{ $fieldName }}" name="{{ $fieldName }}" rows="3" class="form-control" @if($readonly) readonly @endif>{{
|
||||
old($fieldName) ?? ($model->{$fieldName} ? (is_array($model->{$fieldName}) ? json_encode($model->{$fieldName}) : $model->{$fieldName}) : '')
|
||||
}}</textarea>
|
||||
</div>
|
||||
</td>
|
||||
@push('scripts')
|
||||
<script src="https://cdn.ckeditor.com/ckeditor5/27.1.0/classic/ckeditor.js"></script>
|
||||
<script>
|
||||
ClassicEditor
|
||||
.create(
|
||||
document.querySelector( '#{{ $fieldName }}' )
|
||||
)
|
||||
.catch( error => {
|
||||
console.error( error );
|
||||
} );
|
||||
</script>
|
||||
@endpush
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<td>
|
||||
<label for="{{ $fieldName }}" class="form-label">{{ $prop['label'] }}</label>
|
||||
</td>
|
||||
<td>
|
||||
<div class="mb-3">
|
||||
<textarea id="{{ $fieldName }}" name="{{ $fieldName }}" rows="3" class="form-control" @if($readonly) readonly @endif>{{
|
||||
old($fieldName) ?? $model->{$fieldName} ?? ''
|
||||
}}</textarea>
|
||||
</div>
|
||||
</td>
|
||||
@push('scripts')
|
||||
<script src="https://cdn.ckeditor.com/ckeditor5/27.1.0/classic/ckeditor.js"></script>
|
||||
<script>
|
||||
ClassicEditor
|
||||
.create(
|
||||
document.querySelector( '#{{ $fieldName }}' )
|
||||
)
|
||||
.catch( error => {
|
||||
console.error( error );
|
||||
} );
|
||||
</script>
|
||||
@endpush
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
@extends('layout.app')
|
||||
|
||||
@section('title', sprintf('%s - Liste', trans(Str::plural(class_basename($modelClass)))))
|
||||
@section('description', sprintf('Liste des %s', trans(Str::plural(class_basename($modelClass)))))
|
||||
@section('metaIndex', 'noindex,nofollow')
|
||||
|
||||
@section('content')
|
||||
<div class="container container-xxl">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
@include('modules.flashMessage')
|
||||
<div class="card-header">
|
||||
<a href="{{route("$modelTable.index")}}">{{ trans(Str::plural(class_basename($modelClass))) }}</a> - {{ __('Liste') }}
|
||||
@can('create', $modelClass)
|
||||
<a href="{{route("$modelTable.create")}}" class="btn btn-primary float-end">{{ __('Ajouter') }}</a>
|
||||
@endcan
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col">
|
||||
{{ $models->links() }}
|
||||
</div>
|
||||
<div class="col">
|
||||
<form action="{{ url()->current() }}">
|
||||
<div class="input-group mb-3">
|
||||
<input type="search" name="search" class="form-control" value="{{ request()->search }}"/>
|
||||
<input type="text" name="sort_col" class="d-none" value="{{ request()->sort_col }}"/>
|
||||
<input type="text" name="sort_way" class="d-none" value="{{ request()->sort_way }}"/>
|
||||
<a class="btn btn-danger" href="{{ url()->current() }}">Réinitialiser</a>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
{{ __('Recherche') }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<table class="table text-center">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
@foreach ($modelClass::getEditableProperties() as $fieldName => $prop)
|
||||
@if(in_array(CrudAction::viewAny(), $prop['actions']))
|
||||
@switch($prop['type'])
|
||||
@case(CrudType::password())
|
||||
{{-- Ignore --}}
|
||||
@break
|
||||
@default
|
||||
<th scope="col">
|
||||
{{ $prop['label'] }}
|
||||
@include('crud.modules.sorter', ['colname' => $fieldName])
|
||||
</th>
|
||||
@endswitch
|
||||
@endif
|
||||
@endforeach
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@if(count($models))
|
||||
@foreach($models as $model)
|
||||
<tr>
|
||||
@foreach ($modelClass::getEditableProperties() as $fieldName => $prop)
|
||||
@if(in_array(CrudAction::viewAny(), $prop['actions']))
|
||||
@switch($prop['type'])
|
||||
@case(CrudType::password())
|
||||
{{-- Ignore --}}
|
||||
@break
|
||||
@default
|
||||
<td>@include('crud.printfield', [
|
||||
'action' => CrudAction::viewAny(),
|
||||
'field' => $model->{$fieldName},
|
||||
'props' => $prop
|
||||
])</td>
|
||||
@endswitch
|
||||
@endif
|
||||
@endforeach
|
||||
<td>
|
||||
<div class="btn-group" role="group" aria-label="{{ __('Actions') }}">
|
||||
@can('view', $model)
|
||||
<a href="{{route("$modelTable.show", $model)}}" class="btn btn-sm btn-primary">{{ __('Voir') }}</a>
|
||||
@endcan
|
||||
@can('update', $model)
|
||||
<a href="{{route("$modelTable.edit", $model)}}" class="btn btn-sm btn-info">{{ __('Éditer') }}</a>
|
||||
@endcan
|
||||
@can('delete', $model)
|
||||
<form action="{{route("$modelTable.destroy", $model)}}" method="POST" onsubmit="__CRUD.confirmDelete(event)">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="btn btn-sm btn-danger">{{ __('Supprimer') }}</button>
|
||||
</form>
|
||||
@endcan
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
@else
|
||||
<tr>
|
||||
<td colspan="{{ count($modelClass::getEditableProperties()) }}">
|
||||
Rien à afficher
|
||||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
</tbody>
|
||||
</table>
|
||||
{{ $models->links() }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
@php
|
||||
$tableName = (new $modelClass())->getTable();
|
||||
$sortParams = ['sort_col' => $colname];
|
||||
$sortParams = request()->search ?
|
||||
array_merge($sortParams, ['search' => request()->search]) : $sortParams;
|
||||
@endphp
|
||||
@if(!session("crud.$tableName.sort_way") or session("crud.$tableName.sort_col") !== $colname or (session("crud.$tableName.sort_way") === 'desc' and session("crud.$tableName.sort_col") === $colname))
|
||||
<a class="col_sort text-secondary lead asc" href="{{ route("$tableName.index", array_merge($sortParams, ['sort_way' => 'asc'])) }}"> ↓ </a>
|
||||
@endif
|
||||
@if(!session("crud.$tableName.sort_way") or session("crud.$tableName.sort_col") !== $colname or (session("crud.$tableName.sort_way") === 'asc' and session("crud.$tableName.sort_col") === $colname))
|
||||
<a class="col_sort text-secondary lead desc" href="{{ route("$tableName.index", array_merge($sortParams, ['sort_way' => 'desc'])) }}"> ↑ </a>
|
||||
@endif
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
@switch($action)
|
||||
@case(CrudAction::viewAny())
|
||||
@switch($props['type'])
|
||||
@case(CrudType::email())
|
||||
<a href="mailto:$field">{{ $field }}</a>
|
||||
@break
|
||||
@case(CrudType::enum())
|
||||
{{ $model->{$fieldName}->label }}
|
||||
@break
|
||||
@case(CrudType::belongsTo())
|
||||
{{ $prop['belongsTo']::find($model->{$fieldName})->{$model->crudLabelColumn} }}
|
||||
@break
|
||||
@case(CrudType::belongsToMany())
|
||||
{{ $model->{$fieldName}->implode($prop['belongsToManyLabel'], ',') }}
|
||||
@break
|
||||
@case(CrudType::boolean())
|
||||
@if($model->{$fieldName})OUI @else NON @endif
|
||||
@break
|
||||
@case(CrudType::image())
|
||||
<img class="img-responsive" src="{{ sprintf('/storage/%s', $model->{$fieldName}) }}" alt="{{ sprintf('/storage/%s', $model->{$fieldName}) }}">
|
||||
@break
|
||||
@default
|
||||
{{ $field }}
|
||||
@endswitch
|
||||
@break
|
||||
|
||||
@case(CrudAction::view())
|
||||
@switch($props['type'])
|
||||
@case(CrudType::email())
|
||||
<a href="mailto:$field">{{ $field }}</a>
|
||||
@break
|
||||
@case(CrudType::enum())
|
||||
{{ $model->{$fieldName}->label }}
|
||||
@break
|
||||
@case(CrudType::json())
|
||||
@json($field)
|
||||
@break
|
||||
@case(CrudType::boolean())
|
||||
@if($model->{$fieldName})OUI @else NON @endif
|
||||
@break
|
||||
@case(CrudType::image())
|
||||
<img class="img-responsive" src="{{ sprintf('/storage/%s', $model->{$fieldName}) }}" alt="{{ sprintf('/storage/%s', $model->{$fieldName}) }}">
|
||||
@break
|
||||
@case(CrudType::belongsTo())
|
||||
{{ $prop['belongsTo']::find($model->{$fieldName})->{$model->crudLabelColumn} }}
|
||||
@break
|
||||
@case(CrudType::belongsToMany())
|
||||
{{ $model->{$fieldName}->implode($prop['belongsToManyLabel'], ',') }}
|
||||
@break
|
||||
@default
|
||||
{{ $field }}
|
||||
@endswitch
|
||||
@break
|
||||
|
||||
@default
|
||||
@dd('unknown action')
|
||||
@endswitch
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
@extends('layout.app')
|
||||
|
||||
@section('title', sprintf('%s - Voir', trans(Str::plural(class_basename($modelClass)))))
|
||||
@section('description', sprintf('Voir un %s', trans(class_basename($modelClass))))
|
||||
@section('metaIndex', 'noindex,nofollow')
|
||||
|
||||
@section('content')
|
||||
<div class="container container-xxl">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
@include('modules.flashMessage')
|
||||
<div class="card-header">
|
||||
@can('viewAny', $modelClass)
|
||||
<a href="{{route("$modelTable.index")}}">{{ trans(Str::plural(class_basename($modelClass))) }}</a> - {{ __('Voir') }}
|
||||
@else
|
||||
{{ trans(Str::plural(class_basename($modelClass))) }} - {{ __('Voir') }}
|
||||
@endcan
|
||||
<div class="btn-group float-end" role="group" aria-label="{{ __('Actions') }}">
|
||||
@can('update', $model)
|
||||
<a href="{{route("$modelTable.edit", $model)}}" class="btn btn-info ">{{ __('Modifier') }}</a>
|
||||
@endcan
|
||||
@can('delete', $model)
|
||||
<form action="{{route("$modelTable.destroy", $model)}}" method="POST" onsubmit="__CRUD.confirmDelete(event)">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="btn btn-danger">{{ __('Supprimer') }}</button>
|
||||
</form>
|
||||
@endcan
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<table class="table table-sm table-bordered border-primary align-top table-striped text-center">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
<th scope="col" class="w-25">{{ __('Propriété') }}</th>
|
||||
<th scope="col" class="w-75">{{ __('Valeur') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($modelClass::getEditableProperties() as $fieldName => $prop)
|
||||
@if(in_array(CrudAction::view(), $prop['actions']))
|
||||
@switch($prop['type'])
|
||||
@case(CrudType::password())
|
||||
{{-- Ignore --}}
|
||||
@break
|
||||
@default
|
||||
<tr>
|
||||
<td>{{ $prop['label'] }}</td>
|
||||
<td>@include('crud.printfield', [
|
||||
'action' => CrudAction::view(),
|
||||
'field' => $model->{$fieldName},
|
||||
'props' => $prop
|
||||
])</td>
|
||||
</tr>
|
||||
@endswitch
|
||||
@endif
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
|
@ -6,18 +6,18 @@
|
|||
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.16/dist/sweetalert2.all.min.js" integrity="sha256-551HBsteMvKOSqjUXSmRy/EOF0bBNbWB96b5L3Deh8A=" crossorigin="anonymous"></script>
|
||||
|
||||
|
||||
<!-- Styles -->
|
||||
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://bootswatch.com/5/lumen/bootstrap.min.css" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.16/dist/sweetalert2.min.css" integrity="sha256-qpXwccFYncH5gTqXFe9EXZ8QeDw1Re68bbNVfFZzIzg=" crossorigin="anonymous">
|
||||
@crudPoliciesCSS
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="{{ url('/') }}">
|
||||
@if(auth()->user()->site ?? false)
|
||||
Projet : <b class="text-primary">{{ ucwords(auth()->user()->site->name) }}</b>
|
||||
Site : <b class="text-primary">{{ ucwords(auth()->user()->site->name) }}</b>
|
||||
@else
|
||||
{{ config('app.name', 'Laravel') }}
|
||||
@endif
|
||||
|
|
@ -30,7 +30,10 @@
|
|||
<a class="nav-link @if(strpos(request()->route()->getName(), 'ticket') === 0)active @endif" href="{{ route('ticket.index') }}">Tickets</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link @if(strpos(request()->route()->getName(), 'site') === 0)active @endif" href="{{ route('site.index') }}">Projets</a>
|
||||
<a class="nav-link @if(strpos(request()->route()->getName(), 'sites') === 0)active @endif" href="{{ route('sites.index') }}">Sites</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link @if(strpos(request()->route()->getName(), 'projects') === 0)active @endif" href="{{ route('projects.index') }}">Projets</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link @if(strpos(request()->route()->getName(), 'users') === 0)active @endif" href="{{ route('users.index') }}">Utilisateurs</a>
|
||||
|
|
@ -97,12 +100,15 @@
|
|||
</div>
|
||||
</nav>
|
||||
<div id="app" class="content mt-5">
|
||||
@yield('content')
|
||||
<div class="container container-xxl">
|
||||
@yield('content')
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
<script src="https://bootswatch.com/_vendor/bootstrap/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
|
||||
@stack('scriptsConstants')
|
||||
<script src="{{ asset('js/app.js') }}"></script>
|
||||
@stack('scripts')
|
||||
@crudPoliciesJS()
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
108
resources/views/logs/index.blade.php
Normal file
108
resources/views/logs/index.blade.php
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
@extends($viewLayout)
|
||||
|
||||
@section('title', sprintf('%s - %s', transFb(sprintf('models.classes.%s', strtolower(Str::plural(class_basename($modelClass)))), Str::plural(class_basename($modelClass))), __('crud-policies::crud.viewAny')))
|
||||
@section('description', sprintf('%s %s', __('crud-policies::crud.viewAny'), trans(Str::plural(class_basename($modelClass)))))
|
||||
@section('metaIndex', 'noindex,nofollow')
|
||||
|
||||
@section('content')
|
||||
<div class="card">
|
||||
@include('crud-policies::crud.modules.flashMessage')
|
||||
<div class="card-header">
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.index") }}">{{ transFb(sprintf('models.classes.%s', strtolower(Str::plural(class_basename($modelClass)))), Str::plural(class_basename($modelClass))) }}</a> - {{ __('crud-policies::crud.viewAny') }}
|
||||
@can('create', $modelClass)
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.create") }}" class="btn btn-primary float-end">{{ __('crud-policies::crud.create') }}</a>
|
||||
@endcan
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col">
|
||||
{{ $models->links() }}
|
||||
</div>
|
||||
<div class="col">
|
||||
<form action="{{ url()->current() }}">
|
||||
<div class="input-group mb-3">
|
||||
<input type="search" name="search" class="form-control" value="{{ request()->search }}"/>
|
||||
<input type="text" name="sort_col" class="d-none" value="{{ request()->sort_col }}"/>
|
||||
<input type="text" name="sort_way" class="d-none" value="{{ request()->sort_way }}"/>
|
||||
<a class="btn btn-danger" href="{{ url()->current() }}">{{ __('crud-policies::crud.reset') }}</a>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
{{ __('crud-policies::crud.search') }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<table class="table text-center">
|
||||
<thead class="thead-dark">
|
||||
@include('crud-policies::crud.modules.sorter')
|
||||
</thead>
|
||||
<tbody>
|
||||
@if(count($models))
|
||||
|
||||
{{-- INIT QUERIES for OPTIMIZING --}}
|
||||
@foreach ($modelClass::getEditableProperties() as $fieldName => $prop)
|
||||
@if($prop['type']->equals(CrudType::order()))
|
||||
@php ${"$modelTable$fieldName"} = $modelClass::max($fieldName); @endphp
|
||||
@endif
|
||||
@if($prop['type']->equals(CrudType::belongsTo()))
|
||||
@php try { $models->load(Str::singular((new $prop['belongsTo']())->getTable())); } catch(\Exception $e) {} @endphp
|
||||
@endif
|
||||
@if($prop['type']->equals(CrudType::belongsToMany()))
|
||||
@php $models->load("$fieldName"); @endphp
|
||||
@endif
|
||||
@endforeach
|
||||
|
||||
{{-- DISPLAY MODELS --}}
|
||||
@foreach($models as $model)
|
||||
<tr>
|
||||
@foreach ($modelClass::getEditableProperties() as $fieldName => $prop)
|
||||
@if(in_array(CrudAction::viewAny(), $prop['actions']))
|
||||
@switch($prop['type'])
|
||||
@case(CrudType::password())
|
||||
{{-- Ignore --}}
|
||||
@break
|
||||
@default
|
||||
<td>@include('crud-policies::crud.printfield', [
|
||||
'action' => CrudAction::viewAny(),
|
||||
'field' => $model->{$fieldName},
|
||||
'props' => $prop,
|
||||
"$modelTable$fieldName" => ${"$modelTable$fieldName"} ?? null
|
||||
])</td>
|
||||
@endswitch
|
||||
@endif
|
||||
@endforeach
|
||||
|
||||
{{-- MODEL ACTIONS --}}
|
||||
<td>
|
||||
<div class="btn-group" role="group" aria-label="{{ Str::plural(__('crud-policies::crud.action')) }}">
|
||||
@can('view', $model)
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.show", $model) }}" class="btn btn-sm btn-primary">{{ __('crud-policies::crud.view') }}</a>
|
||||
@endcan
|
||||
@can('update', $model)
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.edit", $model) }}" class="btn btn-sm btn-info">{{ __('crud-policies::crud.edit') }}</a>
|
||||
@endcan
|
||||
@can('delete', $model)
|
||||
<form action="{{ CrudController::getRoutePrefixed("$modelTable.destroy", $model) }}" method="POST" onsubmit="__CRUD.confirmDelete(event)">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="btn btn-sm btn-danger">{{ __('crud-policies::crud.delete') }}</button>
|
||||
</form>
|
||||
@endcan
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
@else
|
||||
<tr>
|
||||
<td colspan="{{ count($modelClass::getEditableProperties()) }}">
|
||||
{{ __('crud-policies::crud.nothingtoshow') }}
|
||||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
</tbody>
|
||||
</table>
|
||||
{{ $models->links() }}
|
||||
</div>
|
||||
</div>
|
||||
@include('crud-policies::crud.modules.scriptConstants')
|
||||
@endsection
|
||||
114
resources/views/sites/index.blade.php
Normal file
114
resources/views/sites/index.blade.php
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
@extends($viewLayout)
|
||||
|
||||
@section('title', sprintf('%s - %s', transFb(sprintf('models.classes.%s', strtolower(Str::plural(class_basename($modelClass)))), Str::plural(class_basename($modelClass))), __('crud-policies::crud.viewAny')))
|
||||
@section('description', sprintf('%s %s', __('crud-policies::crud.viewAny'), trans(Str::plural(class_basename($modelClass)))))
|
||||
@section('metaIndex', 'noindex,nofollow')
|
||||
|
||||
@section('content')
|
||||
<div class="card">
|
||||
@include('crud-policies::crud.modules.flashMessage')
|
||||
<div class="card-header">
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.index") }}">{{ transFb(sprintf('models.classes.%s', strtolower(Str::plural(class_basename($modelClass)))), Str::plural(class_basename($modelClass))) }}</a> - {{ __('crud-policies::crud.viewAny') }}
|
||||
@can('create', $modelClass)
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.create") }}" class="btn btn-primary float-end">{{ __('crud-policies::crud.create') }}</a>
|
||||
@endcan
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col">
|
||||
{{ $models->links() }}
|
||||
</div>
|
||||
<div class="col">
|
||||
<form action="{{ url()->current() }}">
|
||||
<div class="input-group mb-3">
|
||||
<input type="search" name="search" class="form-control" value="{{ request()->search }}"/>
|
||||
<input type="text" name="sort_col" class="d-none" value="{{ request()->sort_col }}"/>
|
||||
<input type="text" name="sort_way" class="d-none" value="{{ request()->sort_way }}"/>
|
||||
<a class="btn btn-danger" href="{{ url()->current() }}">{{ __('crud-policies::crud.reset') }}</a>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
{{ __('crud-policies::crud.search') }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<table class="table text-center">
|
||||
<thead class="thead-dark">
|
||||
@include('crud-policies::crud.modules.sorter')
|
||||
</thead>
|
||||
<tbody>
|
||||
@if(count($models))
|
||||
|
||||
{{-- INIT QUERIES for OPTIMIZING --}}
|
||||
@foreach ($modelClass::getEditableProperties() as $fieldName => $prop)
|
||||
@if($prop['type']->equals(CrudType::order()))
|
||||
@php ${"$modelTable$fieldName"} = $modelClass::max($fieldName); @endphp
|
||||
@endif
|
||||
@if($prop['type']->equals(CrudType::belongsTo()))
|
||||
@php try { $models->load(Str::singular((new $prop['belongsTo']())->getTable())); } catch(\Exception $e) {} @endphp
|
||||
@endif
|
||||
@if($prop['type']->equals(CrudType::belongsToMany()))
|
||||
@php $models->load("$fieldName"); @endphp
|
||||
@endif
|
||||
@endforeach
|
||||
|
||||
{{-- DISPLAY MODELS --}}
|
||||
@foreach($models as $model)
|
||||
<tr>
|
||||
@foreach ($modelClass::getEditableProperties() as $fieldName => $prop)
|
||||
@if(in_array(CrudAction::viewAny(), $prop['actions']))
|
||||
@switch($prop['type'])
|
||||
@case(CrudType::password())
|
||||
{{-- Ignore --}}
|
||||
@break
|
||||
@default
|
||||
<td>@include('crud-policies::crud.printfield', [
|
||||
'action' => CrudAction::viewAny(),
|
||||
'field' => $model->{$fieldName},
|
||||
'props' => $prop,
|
||||
"$modelTable$fieldName" => ${"$modelTable$fieldName"} ?? null
|
||||
])</td>
|
||||
@endswitch
|
||||
@endif
|
||||
@endforeach
|
||||
|
||||
{{-- MODEL ACTIONS --}}
|
||||
<td>
|
||||
<div class="btn-group" role="group" aria-label="{{ Str::plural(__('crud-policies::crud.action')) }}">
|
||||
@can('view', $model)
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.show", $model) }}" class="btn btn-sm btn-primary">{{ __('crud-policies::crud.view') }}</a>
|
||||
@endcan
|
||||
@can('update', $model)
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.edit", $model) }}" class="btn btn-sm btn-info">{{ __('crud-policies::crud.edit') }}</a>
|
||||
@endcan
|
||||
@can('delete', $model)
|
||||
<form action="{{ CrudController::getRoutePrefixed("$modelTable.destroy", $model) }}" method="POST" onsubmit="__CRUD.confirmDelete(event)">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="btn btn-sm btn-danger">{{ __('crud-policies::crud.delete') }}</button>
|
||||
</form>
|
||||
@endcan
|
||||
@can('viewAny', \App\Models\Log::class)
|
||||
<a href="{{ CrudController::getRoutePrefixed("sites.logs.index", $model) }}" class="btn btn-sm btn-dark">{{ __('Journaux') }}</a>
|
||||
@endcan
|
||||
@can('viewAny', \App\Models\File::class)
|
||||
<a href="{{ CrudController::getRoutePrefixed("sites.files.index", $model) }}" class="btn btn-sm btn-dark">{{ __('Fichiers') }}</a>
|
||||
@endcan
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
@else
|
||||
<tr>
|
||||
<td colspan="{{ count($modelClass::getEditableProperties()) }}">
|
||||
{{ __('crud-policies::crud.nothingtoshow') }}
|
||||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
</tbody>
|
||||
</table>
|
||||
{{ $models->links() }}
|
||||
</div>
|
||||
</div>
|
||||
@include('crud-policies::crud.modules.scriptConstants')
|
||||
@endsection
|
||||
48
resources/views/vendor/crud-policies/crud/create.blade.php
vendored
Normal file
48
resources/views/vendor/crud-policies/crud/create.blade.php
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
@extends($viewLayout)
|
||||
|
||||
@section('title', sprintf('%s - %s', transFb(sprintf('models.classes.%s', strtolower(Str::plural(class_basename($modelClass)))), Str::plural(class_basename($modelClass))), __('crud-policies::crud.create')))
|
||||
@section('description', sprintf('%s %s', __('crud-policies::crud.create'), class_basename($modelClass)))
|
||||
@section('metaIndex', 'noindex,nofollow')
|
||||
|
||||
@section('content')
|
||||
<div class="card">
|
||||
@include('crud-policies::crud.modules.flashMessage')
|
||||
<div class="card-header">
|
||||
@can('viewAny', $modelClass)
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.index") }}">{{ transFb(sprintf('models.classes.%s', strtolower(Str::plural(class_basename($modelClass)))), Str::plural(class_basename($modelClass))) }}</a> - {{ __('crud-policies::crud.create') }}
|
||||
@else
|
||||
{{ Str::plural(class_basename($modelClass)) }} - {{ __('crud-policies::crud.create') }}
|
||||
@endcan
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="{{ CrudController::getRoutePrefixed("$modelTable.store") }}" method="POST" @if($hasImage) enctype="multipart/form-data" @endif>
|
||||
@csrf
|
||||
<table class="table table-sm table-bordered border-primary align-middle table-striped text-center">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
<th scope="col" class="w-25">{{ __('crud-policies::crud.property') }}</th>
|
||||
<th scope="col" class="w-75">{{ __('crud-policies::crud.value') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($modelClass::getEditableProperties() as $fieldName => $prop)
|
||||
@php
|
||||
// create form cannot accept readonly field
|
||||
$prop['readonly'] = false;
|
||||
@endphp
|
||||
@if(in_array(CrudAction::create(), $prop['actions']))
|
||||
<tr>
|
||||
@include('crud-policies::crud.formfield')
|
||||
</tr>
|
||||
@endif
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="col text-center">
|
||||
<button class="btn btn-info" type="submit">{{ __('crud-policies::crud.create') }}</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@include('crud-policies::crud.modules.scriptConstants')
|
||||
@endsection
|
||||
57
resources/views/vendor/crud-policies/crud/edit.blade.php
vendored
Normal file
57
resources/views/vendor/crud-policies/crud/edit.blade.php
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
@extends($viewLayout)
|
||||
|
||||
@section('title', sprintf('%s - %s', transFb(sprintf('models.classes.%s', strtolower(Str::plural(class_basename($modelClass)))), Str::plural(class_basename($modelClass))), __('crud-policies::crud.edit')))
|
||||
@section('description', sprintf('%s %s', __('crud-policies::crud.edit'), trans(class_basename($modelClass))))
|
||||
@section('metaIndex', 'noindex,nofollow')
|
||||
|
||||
@section('content')
|
||||
<div class="card">
|
||||
@include('crud-policies::crud.modules.flashMessage')
|
||||
<div class="card-header">
|
||||
@can('viewAny', $modelClass)
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.index") }}">{{ transFb(sprintf('models.classes.%s', strtolower(Str::plural(class_basename($modelClass)))), Str::plural(class_basename($modelClass))) }}</a> - {{ __('crud-policies::crud.edit') }}
|
||||
@else
|
||||
{{ trans(Str::plural(class_basename($modelClass))) }} - {{ __('crud-policies::crud.edit') }}
|
||||
@endcan
|
||||
<div class="btn-group float-end" role="group" aria-label="{{ __('crud-policies::crud.action') }}">
|
||||
@can('view', $model)
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.show", $model) }}" class="btn btn-primary ">{{ __('crud-policies::crud.view') }}</a>
|
||||
@endcan
|
||||
@can('delete', $model)
|
||||
<form action="{{ CrudController::getRoutePrefixed("$modelTable.destroy", $model) }}" method="POST" onsubmit="__CRUD.confirmDelete(event)">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="btn btn-danger">{{ __('crud-policies::crud.delete') }}</button>
|
||||
</form>
|
||||
@endcan
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="{{ CrudController::getRoutePrefixed("$modelTable.update", $model) }}" method="POST" @if($hasImage) enctype="multipart/form-data" @endif>
|
||||
@method('put')
|
||||
@csrf
|
||||
<table class="table table-sm table-bordered border-primary align-middle table-striped text-center">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
<th scope="col" class="w-25">{{ __('crud-policies::crud.property') }}</th>
|
||||
<th scope="col" class="w-75">{{ __('crud-policies::crud.value') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($modelClass::getEditableProperties() as $fieldName => $prop)
|
||||
@if(in_array(CrudAction::update(), $prop['actions']))
|
||||
<tr>
|
||||
@include('crud-policies::crud.formfield')
|
||||
</tr>
|
||||
@endif
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="col text-center">
|
||||
<button class="btn btn-info" type="submit">{{ __('crud-policies::crud.update') }}</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@include('crud-policies::crud.modules.scriptConstants')
|
||||
@endsection
|
||||
53
resources/views/vendor/crud-policies/crud/formfield.blade.php
vendored
Normal file
53
resources/views/vendor/crud-policies/crud/formfield.blade.php
vendored
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
@php
|
||||
$readonly = is_callable($prop['readonly']) ? $prop['readonly']() : $prop['readonly'];
|
||||
@endphp
|
||||
@switch($prop['type'])
|
||||
@case(CrudType::password())
|
||||
@include('crud-policies::crud.formfields.password')
|
||||
@break
|
||||
@case(CrudType::boolean())
|
||||
@include('crud-policies::crud.formfields.boolean')
|
||||
@break
|
||||
@case(CrudType::int())
|
||||
@include('crud-policies::crud.formfields.int')
|
||||
@break
|
||||
@case(CrudType::float())
|
||||
@include('crud-policies::crud.formfields.float')
|
||||
@break
|
||||
@case(CrudType::unsignedint())
|
||||
@include('crud-policies::crud.formfields.int', ['unsigned' => true])
|
||||
@break
|
||||
@case(CrudType::unsignedfloat())
|
||||
@include('crud-policies::crud.formfields.float', ['unsigned' => true])
|
||||
@break
|
||||
@case(CrudType::email())
|
||||
@include('crud-policies::crud.formfields.email')
|
||||
@break
|
||||
@case(CrudType::text())
|
||||
@include('crud-policies::crud.formfields.text')
|
||||
@break
|
||||
@case(CrudType::json())
|
||||
@include('crud-policies::crud.formfields.json')
|
||||
@break
|
||||
@case(CrudType::image())
|
||||
@include('crud-policies::crud.formfields.image')
|
||||
@break
|
||||
@case(CrudType::enum())
|
||||
@include('crud-policies::crud.formfields.enum')
|
||||
@break
|
||||
@case(CrudType::order())
|
||||
@include('crud-policies::crud.formfields.order')
|
||||
@break
|
||||
@case(CrudType::color())
|
||||
@include('crud-policies::crud.formfields.color')
|
||||
@break
|
||||
@case(CrudType::belongsTo())
|
||||
@include('crud-policies::crud.formfields.belongsTo')
|
||||
@break
|
||||
@case(CrudType::belongsToMany())
|
||||
@include('crud-policies::crud.formfields.belongsToMany')
|
||||
@break
|
||||
@case(CrudType::string())
|
||||
@default
|
||||
@include('crud-policies::crud.formfields.string')
|
||||
@endswitch
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
<td>
|
||||
<belongs-to
|
||||
readonly="{{ $readonly }}"
|
||||
tablename="{{ $modelTable }}"
|
||||
name="{{ $fieldName }}"
|
||||
db-value='@json($related)'>
|
||||
</belongs-to>
|
||||
|
|
@ -20,11 +21,12 @@
|
|||
|
||||
@push('scriptsConstants')
|
||||
<script>
|
||||
window._locale = '{{ app()->getLocale() }}';
|
||||
window._translations = @json(cache(sprintf('translations.%s', app()->getLocale())));
|
||||
window._asset = '{{ asset('') }}';
|
||||
window._routes = {
|
||||
'model.index': '{{ route((new $props[$fieldName]['belongsTo'])->getTable().'.index') }}'
|
||||
};
|
||||
if (!window.__CRUD) {
|
||||
window.__CRUD = {};
|
||||
}
|
||||
if(!window.__CRUD._routes) {
|
||||
window.__CRUD._routes = {};
|
||||
}
|
||||
window.__CRUD._routes['{{$modelTable}}.{{$fieldName}}.model.index'] = '{{ CrudController::getRoutePrefixed((new $props[$fieldName]['belongsTo'])->getTable().'.index') }}';
|
||||
</script>
|
||||
@endpush
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
<td>
|
||||
<belongs-to-many
|
||||
readonly="{{ $readonly }}"
|
||||
tablename="{{ $modelTable }}"
|
||||
name="{{ $fieldName }}"
|
||||
db-value='@json($related)'>
|
||||
</belongs-to-many>
|
||||
|
|
@ -19,11 +20,12 @@
|
|||
|
||||
@push('scriptsConstants')
|
||||
<script>
|
||||
window._locale = '{{ app()->getLocale() }}';
|
||||
window._translations = @json(cache(sprintf('translations.%s', app()->getLocale())));
|
||||
window._asset = '{{ asset('') }}';
|
||||
window._routes = {
|
||||
'model.index': '{{ route((new $props[$fieldName]['belongsToMany'])->getTable().'.index') }}'
|
||||
};
|
||||
if (!window.__CRUD) {
|
||||
window.__CRUD = {};
|
||||
}
|
||||
if(!window.__CRUD._routes) {
|
||||
window.__CRUD._routes = {};
|
||||
}
|
||||
window.__CRUD._routes['{{$modelTable}}.{{$fieldName}}.model.index'] = '{{ CrudController::getRoutePrefixed((new $props[$fieldName]['belongsToMany'])->getTable().'.index') }}';
|
||||
</script>
|
||||
@endpush
|
||||
|
|
@ -9,9 +9,9 @@
|
|||
id="{{ $fieldName }}"
|
||||
name="{{ $fieldName }}"
|
||||
type="checkbox"
|
||||
class="ms-2 form-check-input"
|
||||
class="ml-2 form-check-input"
|
||||
value="1"
|
||||
@if(old($fieldName) ?? ((isset($model) and $model->{$fieldName}) ? $model->{$fieldName} : false))checked @endif
|
||||
@if(old($fieldName) ?? ((isset($model) and $model->{$fieldName}) ? $model->{$fieldName} : $prop['default'] ?? false))checked @endif
|
||||
@if($prop['disabled'])disabled @endif
|
||||
@if($readonly)readonly @endif>
|
||||
</div>
|
||||
32
resources/views/vendor/crud-policies/crud/formfields/color.blade.php
vendored
Normal file
32
resources/views/vendor/crud-policies/crud/formfields/color.blade.php
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<td>
|
||||
<label for="{{ $fieldName }}" class="form-label">{{ $prop['label'] }}</label>
|
||||
</td>
|
||||
<td>
|
||||
@if(strlen($prop['placeholder']))
|
||||
<div class="form-floating">
|
||||
<input
|
||||
id="{{ $fieldName }}"
|
||||
name="{{ $fieldName }}"
|
||||
type="text"
|
||||
data-jscolor=""
|
||||
class="form-control"
|
||||
value="{{ old($fieldName) ?? $model->{$fieldName} ?? $prop['default'] ?? '' }}"
|
||||
@if($prop['disabled'])disabled @endif
|
||||
@if($readonly)readonly @endif
|
||||
@if($prop['required'] or (!$prop['required'] and !$prop['nullable']))required @endif>
|
||||
<label for="{{ $fieldName }}" class="form-label">{{ __('ex: :placeholder', ['placeholder' => $prop['placeholder']]) }}</label>
|
||||
</div>
|
||||
@else
|
||||
<input
|
||||
id="{{ $fieldName }}"
|
||||
name="{{ $fieldName }}"
|
||||
type="text"
|
||||
data-jscolor=""
|
||||
class="form-control"
|
||||
value="{{ old($fieldName) ?? $model->{$fieldName} ?? $prop['default'] ?? '' }}"
|
||||
@if($prop['disabled'])disabled @endif
|
||||
@if($readonly)readonly @endif
|
||||
@if($prop['required'] or (!$prop['required'] and !$prop['nullable']))required @endif>
|
||||
@endif
|
||||
</td>
|
||||
@include('crud-policies::crud.modules.color')
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
name="{{ $fieldName }}"
|
||||
type="email"
|
||||
class="form-control"
|
||||
value="{{ old($fieldName) ?? $model->{$fieldName} ?? '' }}"
|
||||
value="{{ old($fieldName) ?? $model->{$fieldName} ?? $prop['default'] ?? '' }}"
|
||||
@if(isset($prop['rules']['max']))maxlength="{{ $prop['rules']['max'] }}"@endif
|
||||
@if(isset($prop['rules']['min']))minlength="{{ $prop['rules']['min'] }}"@endif
|
||||
@if($prop['disabled'])disabled @endif
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
name="{{ $fieldName }}"
|
||||
type="email"
|
||||
class="form-control"
|
||||
value="{{ old($fieldName) ?? $model->{$fieldName} ?? '' }}"
|
||||
value="{{ old($fieldName) ?? $model->{$fieldName} ?? $prop['default'] ?? '' }}"
|
||||
@if(isset($prop['rules']['max']))maxlength="{{ $prop['rules']['max'] }}"@endif
|
||||
@if(isset($prop['rules']['min']))minlength="{{ $prop['rules']['min'] }}"@endif
|
||||
@if($prop['disabled'])disabled @endif
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
<label for="{{ $fieldName }}" class="form-label">{{ $prop['label'] }}</label>
|
||||
</td>
|
||||
<td>
|
||||
<select id="{{ $fieldName }}" class="form-control" name="{{ $fieldName }}" @if($prop['readonly']) readonly @endif @if($prop['disabled']) disabled @endif>
|
||||
<select id="{{ $fieldName }}" class="form-control" name="{{ $fieldName }}" @if($readonly) readonly @endif @if($prop['disabled']) disabled @endif>
|
||||
{{-- TODO handle enum nullable ? --}}
|
||||
{{-- @if($prop['nullable'])
|
||||
@endif --}}
|
||||
|
|
@ -7,8 +7,12 @@
|
|||
class="form-control"
|
||||
name="{{ $fieldName }}"
|
||||
type="number"
|
||||
placeholder="{{ $prop['rules']['min'] }}"
|
||||
value="{{ old($fieldName) ?? $model->{$fieldName} ?? $prop['rules']['min'] }}"
|
||||
placeholder="{{ $prop['placeholder'] }}"
|
||||
step="0.000001"
|
||||
@if(isset($unsigned))
|
||||
min="0"
|
||||
@endif
|
||||
value="{{ old($fieldName) ?? $model->{$fieldName} ?? $prop['rules']['min'] ?? $prop['default'] ?? 0 }}"
|
||||
@if(isset($prop['rules']['max']))max="{{ $prop['rules']['max'] }}"@endif
|
||||
@if(isset($prop['rules']['min']))min="{{ $prop['rules']['min'] }}"@endif
|
||||
@if(isset($prop['rules']['step']))step="{{ $prop['rules']['step'] }}"@endif
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
name="{{ $fieldName }}"
|
||||
type="file"
|
||||
class="form-control"
|
||||
value="{{ old($fieldName) ?? $model->{$fieldName} ?? '' }}"
|
||||
value="{{ old($fieldName) ?? $model->{$fieldName} ?? $prop['default'] ?? '' }}"
|
||||
@if(isset($prop['rules']['max']))maxlength="{{ $prop['rules']['max'] }}"@endif
|
||||
@if(isset($prop['rules']['min']))minlength="{{ $prop['rules']['min'] }}"@endif
|
||||
@if($prop['disabled'])disabled @endif
|
||||
|
|
@ -7,8 +7,11 @@
|
|||
class="form-control"
|
||||
name="{{ $fieldName }}"
|
||||
type="number"
|
||||
placeholder="{{ $prop['rules']['min'] }}"
|
||||
value="{{ old($fieldName) ?? $model->{$fieldName} ?? $prop['rules']['min'] }}"
|
||||
placeholder="{{ $prop['placeholder'] }}"
|
||||
@if(isset($unsigned))
|
||||
min="0"
|
||||
@endif
|
||||
value="{{ old($fieldName) ?? $model->{$fieldName} ?? $prop['rules']['min'] ?? $prop['default'] ?? 0 }}"
|
||||
@if(isset($prop['rules']['max']))max="{{ $prop['rules']['max'] }}"@endif
|
||||
@if(isset($prop['rules']['min']))min="{{ $prop['rules']['min'] }}"@endif
|
||||
@if(isset($prop['rules']['step']))step="{{ $prop['rules']['step'] }}"@endif
|
||||
23
resources/views/vendor/crud-policies/crud/formfields/json.blade.php
vendored
Normal file
23
resources/views/vendor/crud-policies/crud/formfields/json.blade.php
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
@php
|
||||
$jsonValue = old($fieldName) ?? (
|
||||
(isset($model) and $model->{$fieldName}) ?
|
||||
(
|
||||
is_array($model->{$fieldName}) ?
|
||||
json_encode($model->{$fieldName}) : $model->{$fieldName}
|
||||
) : $prop['default']
|
||||
);
|
||||
@endphp
|
||||
<td>
|
||||
<label for="{{ $fieldName }}" class="form-label">{{ $prop['label'] }}</label>
|
||||
</td>
|
||||
<td>
|
||||
<div class="mb-3">
|
||||
<div id="{{ $fieldName }}jsoneditor"></div>
|
||||
<textarea id="{{ $fieldName }}" name="{{ $fieldName }}" rows="3" class="form-control d-none" @if($readonly) readonly @endif>{!! $jsonValue !!}</textarea>
|
||||
</div>
|
||||
</td>
|
||||
@include('crud-policies::crud.modules.jsoneditor', [
|
||||
'fieldName' => $fieldName,
|
||||
'value' => $jsonValue,
|
||||
'prop' => $prop
|
||||
])
|
||||
19
resources/views/vendor/crud-policies/crud/formfields/order.blade.php
vendored
Normal file
19
resources/views/vendor/crud-policies/crud/formfields/order.blade.php
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<td>
|
||||
<label for="{{ $fieldName }}" class="form-label">{{ $prop['label'] }}</label>
|
||||
</td>
|
||||
<td>
|
||||
<select
|
||||
id="{{ $fieldName }}"
|
||||
name="{{ $fieldName }}"
|
||||
class="form-control"
|
||||
@if($readonly)readonly @endif
|
||||
@if($prop['required'] or (!$prop['required'] and !$prop['nullable']))required @endif
|
||||
@if($prop['disabled'])disabled @endif>
|
||||
@foreach($modelClass::orderBy($fieldName)->pluck($fieldName) as $order)
|
||||
<option value="{{ $order }}" @if(isset($model) and $model->order === $order)selected @endif>{{ $order }}</option>
|
||||
@endforeach
|
||||
@if(!isset($model))
|
||||
<option value="{{ $modelClass::pluck($fieldName)->max() +1 }}" selected>{{ $modelClass::pluck($fieldName)->max() +1 }}</option>
|
||||
@endif
|
||||
</select>
|
||||
</td>
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
name="{{ $fieldName }}"
|
||||
type="text"
|
||||
class="form-control"
|
||||
value="{{ old($fieldName) ?? $model->{$fieldName} ?? '' }}"
|
||||
value="{{ old($fieldName) ?? $model->{$fieldName} ?? $prop['default'] ?? '' }}"
|
||||
@if(isset($prop['rules']['max']))maxlength="{{ $prop['rules']['max'] }}"@endif
|
||||
@if(isset($prop['rules']['min']))minlength="{{ $prop['rules']['min'] }}"@endif
|
||||
@if($prop['disabled'])disabled @endif
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
name="{{ $fieldName }}"
|
||||
type="text"
|
||||
class="form-control"
|
||||
value="{{ old($fieldName) ?? $model->{$fieldName} ?? '' }}"
|
||||
value="{{ old($fieldName) ?? $model->{$fieldName} ?? $prop['default'] ?? '' }}"
|
||||
@if(isset($prop['rules']['max']))maxlength="{{ $prop['rules']['max'] }}"@endif
|
||||
@if(isset($prop['rules']['min']))minlength="{{ $prop['rules']['min'] }}"@endif
|
||||
@if($prop['disabled'])disabled @endif
|
||||
13
resources/views/vendor/crud-policies/crud/formfields/text.blade.php
vendored
Normal file
13
resources/views/vendor/crud-policies/crud/formfields/text.blade.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<td>
|
||||
<label for="{{ $fieldName }}" class="form-label">{{ $prop['label'] }}</label>
|
||||
</td>
|
||||
<td>
|
||||
<div class="mb-3">
|
||||
<textarea id="{{ $fieldName }}" name="{{ $fieldName }}" rows="3" class="form-control" @if($readonly) readonly @endif>{{
|
||||
old($fieldName) ?? $model->{$fieldName} ?? $prop['default'] ?? ''
|
||||
}}</textarea>
|
||||
</div>
|
||||
</td>
|
||||
@include('crud-policies::crud.modules.ckeditor', [
|
||||
'fieldName' => $fieldName
|
||||
])
|
||||
108
resources/views/vendor/crud-policies/crud/index.blade.php
vendored
Normal file
108
resources/views/vendor/crud-policies/crud/index.blade.php
vendored
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
@extends($viewLayout)
|
||||
|
||||
@section('title', sprintf('%s - %s', transFb(sprintf('models.classes.%s', strtolower(Str::plural(class_basename($modelClass)))), Str::plural(class_basename($modelClass))), __('crud-policies::crud.viewAny')))
|
||||
@section('description', sprintf('%s %s', __('crud-policies::crud.viewAny'), trans(Str::plural(class_basename($modelClass)))))
|
||||
@section('metaIndex', 'noindex,nofollow')
|
||||
|
||||
@section('content')
|
||||
<div class="card">
|
||||
@include('crud-policies::crud.modules.flashMessage')
|
||||
<div class="card-header">
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.index") }}">{{ transFb(sprintf('models.classes.%s', strtolower(Str::plural(class_basename($modelClass)))), Str::plural(class_basename($modelClass))) }}</a> - {{ __('crud-policies::crud.viewAny') }}
|
||||
@can('create', $modelClass)
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.create") }}" class="btn btn-primary float-end">{{ __('crud-policies::crud.create') }}</a>
|
||||
@endcan
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col">
|
||||
{{ $models->links() }}
|
||||
</div>
|
||||
<div class="col">
|
||||
<form action="{{ url()->current() }}">
|
||||
<div class="input-group mb-3">
|
||||
<input type="search" name="search" class="form-control" value="{{ request()->search }}"/>
|
||||
<input type="text" name="sort_col" class="d-none" value="{{ request()->sort_col }}"/>
|
||||
<input type="text" name="sort_way" class="d-none" value="{{ request()->sort_way }}"/>
|
||||
<a class="btn btn-danger" href="{{ url()->current() }}">{{ __('crud-policies::crud.reset') }}</a>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
{{ __('crud-policies::crud.search') }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<table class="table text-center">
|
||||
<thead class="thead-dark">
|
||||
@include('crud-policies::crud.modules.sorter')
|
||||
</thead>
|
||||
<tbody>
|
||||
@if(count($models))
|
||||
|
||||
{{-- INIT QUERIES for OPTIMIZING --}}
|
||||
@foreach ($modelClass::getEditableProperties() as $fieldName => $prop)
|
||||
@if($prop['type']->equals(CrudType::order()))
|
||||
@php ${"$modelTable$fieldName"} = $modelClass::max($fieldName); @endphp
|
||||
@endif
|
||||
@if($prop['type']->equals(CrudType::belongsTo()))
|
||||
@php try { $models->load(Str::singular((new $prop['belongsTo']())->getTable())); } catch(\Exception $e) {} @endphp
|
||||
@endif
|
||||
@if($prop['type']->equals(CrudType::belongsToMany()))
|
||||
@php $models->load("$fieldName"); @endphp
|
||||
@endif
|
||||
@endforeach
|
||||
|
||||
{{-- DISPLAY MODELS --}}
|
||||
@foreach($models as $model)
|
||||
<tr>
|
||||
@foreach ($modelClass::getEditableProperties() as $fieldName => $prop)
|
||||
@if(in_array(CrudAction::viewAny(), $prop['actions']))
|
||||
@switch($prop['type'])
|
||||
@case(CrudType::password())
|
||||
{{-- Ignore --}}
|
||||
@break
|
||||
@default
|
||||
<td>@include('crud-policies::crud.printfield', [
|
||||
'action' => CrudAction::viewAny(),
|
||||
'field' => $model->{$fieldName},
|
||||
'props' => $prop,
|
||||
"$modelTable$fieldName" => ${"$modelTable$fieldName"} ?? null
|
||||
])</td>
|
||||
@endswitch
|
||||
@endif
|
||||
@endforeach
|
||||
|
||||
{{-- MODEL ACTIONS --}}
|
||||
<td>
|
||||
<div class="btn-group" role="group" aria-label="{{ Str::plural(__('crud-policies::crud.action')) }}">
|
||||
@can('view', $model)
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.show", $model) }}" class="btn btn-sm btn-primary">{{ __('crud-policies::crud.view') }}</a>
|
||||
@endcan
|
||||
@can('update', $model)
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.edit", $model) }}" class="btn btn-sm btn-info">{{ __('crud-policies::crud.edit') }}</a>
|
||||
@endcan
|
||||
@can('delete', $model)
|
||||
<form action="{{ CrudController::getRoutePrefixed("$modelTable.destroy", $model) }}" method="POST" onsubmit="__CRUD.confirmDelete(event)">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="btn btn-sm btn-danger">{{ __('crud-policies::crud.delete') }}</button>
|
||||
</form>
|
||||
@endcan
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
@else
|
||||
<tr>
|
||||
<td colspan="{{ count($modelClass::getEditableProperties()) }}">
|
||||
{{ __('crud-policies::crud.nothingtoshow') }}
|
||||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
</tbody>
|
||||
</table>
|
||||
{{ $models->links() }}
|
||||
</div>
|
||||
</div>
|
||||
@include('crud-policies::crud.modules.scriptConstants')
|
||||
@endsection
|
||||
90
resources/views/vendor/crud-policies/crud/layout.blade.php
vendored
Normal file
90
resources/views/vendor/crud-policies/crud/layout.blade.php
vendored
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<!doctype html>
|
||||
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
|
||||
<head>
|
||||
<title>{{ config('app.name') }}@hasSection('title') - @yield('title')@endif</title>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<meta name="description" content="@yield('description')">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<meta name="robots" content="index, follow">
|
||||
<link rel="canonical" href="{{ url()->current() }}" />
|
||||
|
||||
<!-- STYLES -->
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" integrity="sha256-hHKA3d/HttC8OW3Sl093W8DoZudhHJDj++kZYo6MLzA=" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.16/dist/sweetalert2.min.css" integrity="sha256-qpXwccFYncH5gTqXFe9EXZ8QeDw1Re68bbNVfFZzIzg=" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="{{ route('crud-policies.httpFileSend.asset', [
|
||||
'type' => 'css',
|
||||
'fileUri' => 'crud.css'
|
||||
]) }}">
|
||||
|
||||
@stack('styles')
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark sticky-top">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/">{{ config('app.name') }}</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarScroll" aria-controls="navbarScroll" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarScroll">
|
||||
<ul class="navbar-nav ms-auto my-2 my-lg-0 navbar-nav-scroll " style="--bs-scroll-height: 100px;">
|
||||
@auth()
|
||||
<li class="nav-item"><span class="nav-link text-success">{{ auth()->user()->name }}</span></li>
|
||||
@endauth
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
@if(isset($modelsClasses))
|
||||
<nav id="sidebarMenu" class="col-md-3 col-lg-2 min-height-100vh d-md-block bg-light sidebar collapse">
|
||||
<div class="sidebar-sticky pt-3 d-flex flex-column justify-content-between align-items-center">
|
||||
<div class="col-12 mt-4">
|
||||
@foreach($modelsClasses as $crudModel)
|
||||
@if(
|
||||
auth()->user()->can('viewAny', $crudModel) or
|
||||
auth()->user()->can('create', $crudModel)
|
||||
)
|
||||
<h6 class="sidebar-heading px-3 mb-1 text-muted">
|
||||
<span>{{ __(ucfirst(collect(explode('\\', $crudModel))->last())) }}</span>
|
||||
</h6>
|
||||
@php
|
||||
$crudModel = new $crudModel();
|
||||
@endphp
|
||||
<ul class="nav flex-column mb-2">
|
||||
@can('viewAny', $crudModel)
|
||||
<li class="nav-item"><a class="nav-link" href="{{ CrudController::getRoutePrefixed(sprintf('%s.index', $crudModel->getTable())) }}">{{ __('crud-policies::crud.viewAny') }}</a></li>
|
||||
@endcan
|
||||
@can('create', $crudModel)
|
||||
<li class="nav-item"><a class="nav-link" href="{{ CrudController::getRoutePrefixed(sprintf('%s.create', $crudModel->getTable())) }}">{{ __('crud-policies::crud.create') }}</a></li>
|
||||
@endcan
|
||||
</ul>
|
||||
<hr>
|
||||
@endcan
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main role="main" class="col-md-9 mt-5 mb-5 ml-sm-auto col-lg-10 px-md-4">
|
||||
@else
|
||||
<main role="main" class="mt-5 mb-5">
|
||||
@endif
|
||||
@yield('content')
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@stack('scriptsConstants')
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha256-edRDsV9ULIqKzKjpN/KjyQ7Lp4vUn9usbJuHjH8Sk+k=" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.16/dist/sweetalert2.all.min.js" integrity="sha256-551HBsteMvKOSqjUXSmRy/EOF0bBNbWB96b5L3Deh8A=" crossorigin="anonymous"></script>
|
||||
<script src="//cdn.jsdelivr.net/npm/sweetalert2@10"></script>
|
||||
<script src="{{ route('crud-policies.httpFileSend.asset', [
|
||||
'type' => 'js',
|
||||
'fileUri' => 'crud.js'
|
||||
]) }}"></script>
|
||||
@stack('scripts')
|
||||
</body>
|
||||
</html>
|
||||
15
resources/views/vendor/crud-policies/crud/modules/ckeditor.blade.php
vendored
Normal file
15
resources/views/vendor/crud-policies/crud/modules/ckeditor.blade.php
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
@push('scripts')
|
||||
@if(!isset($ckeditorInput))
|
||||
@php View::share('ckeditorInput', true) @endphp
|
||||
<script src="https://cdn.ckeditor.com/ckeditor5/27.1.0/classic/ckeditor.js"></script>
|
||||
@endif
|
||||
<script>
|
||||
ClassicEditor
|
||||
.create(
|
||||
document.querySelector( '#{{ $fieldName }}' )
|
||||
)
|
||||
.catch( error => {
|
||||
console.error( error );
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
6
resources/views/vendor/crud-policies/crud/modules/color.blade.php
vendored
Normal file
6
resources/views/vendor/crud-policies/crud/modules/color.blade.php
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
@if(!isset($CrudColorLib))
|
||||
@push('scripts')
|
||||
@php View::share('CrudColorLib', true) @endphp
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jscolor/2.4.5/jscolor.min.js"></script>
|
||||
@endpush
|
||||
@endif
|
||||
44
resources/views/vendor/crud-policies/crud/modules/flashMessage.blade.php
vendored
Normal file
44
resources/views/vendor/crud-policies/crud/modules/flashMessage.blade.php
vendored
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
@if ($message = Session::get('success'))
|
||||
<div class="alert alert-success alert-dismissible fade show">
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="{{ __('crud-policies::crud.close') }}"></button>
|
||||
<strong>{!! nl2br(e($message)) !!}</strong>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
|
||||
@if ($message = Session::get('error'))
|
||||
<div class="alert alert-danger alert-dismissible fade show">
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="{{ __('crud-policies::crud.close') }}"></button>
|
||||
<strong>{!! nl2br(e($message)) !!}</strong>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
|
||||
@if ($message = Session::get('warning'))
|
||||
<div class="alert alert-warning alert-dismissible fade show">
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="{{ __('crud-policies::crud.close') }}"></button>
|
||||
<strong>{!! nl2br(e($message)) !!}</strong>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
|
||||
@if ($message = Session::get('info'))
|
||||
<div class="alert alert-info alert-dismissible fade show">
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="{{ __('crud-policies::crud.close') }}"></button>
|
||||
<strong>{!! nl2br(e($message)) !!}</strong>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
|
||||
@if ($errors->any())
|
||||
<div class="alert alert-danger alert-dismissible fade show">
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="{{ __('crud-policies::crud.close') }}"></button>
|
||||
@if ($errors->any())
|
||||
<ul class="list-unstyled">
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
27
resources/views/vendor/crud-policies/crud/modules/jsoneditor.blade.php
vendored
Normal file
27
resources/views/vendor/crud-policies/crud/modules/jsoneditor.blade.php
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
@if(!isset($JsonEditor))
|
||||
@push('scripts')
|
||||
@php View::share('JsonEditor', true) @endphp
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/9.5.1/jsoneditor.min.js" integrity="sha512-NA6kPrAqyMsKDzpFPDLTE9TJn1iwCXSQOSIpdWBgVJMrnNIeYZECh8ePT5QI1tBVN6ZiTklWW3RKOLlxQDfMkA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
@endpush
|
||||
@push('styles')
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/9.5.1/jsoneditor.min.css" integrity="sha512-ZS7UFcBWqviCnOtlrIz47Z10BQYs/qYJLIh/uUIVHRBjJ2zDVZ7ALvPssEqRLDObR66r5fEaY8NaLvIOOxQ1Vw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||
@endpush
|
||||
@endif
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
let container = document.getElementById('{{ $fieldName.'jsoneditor' }}');
|
||||
let input = document.getElementById('{{ $fieldName }}');
|
||||
window.editor = new JSONEditor(container, {
|
||||
mode: '{{ $prop['mode'] }}',
|
||||
modes: {!! json_encode($prop['modes']) !!},
|
||||
indentation: 2,
|
||||
onError: function(error) {
|
||||
console.log(error);
|
||||
},
|
||||
onChange: function() {
|
||||
input.value = JSON.stringify(editor.getText());
|
||||
}
|
||||
}, {!! $jsonValue !!})
|
||||
</script>
|
||||
@endpush
|
||||
10
resources/views/vendor/crud-policies/crud/modules/scriptConstants.blade.php
vendored
Normal file
10
resources/views/vendor/crud-policies/crud/modules/scriptConstants.blade.php
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
@push('scriptsConstants')
|
||||
<script>
|
||||
if (!window.__CRUD) {
|
||||
window.__CRUD = {};
|
||||
}
|
||||
window.__CRUD._locale = '{{ app()->getLocale() }}';
|
||||
window.__CRUD._translations = @json(cache(sprintf('crud-policies.translations.%s', app()->getLocale())) ?? '{}');
|
||||
window.__CRUD._asset = '{{ asset('') }}';
|
||||
</script>
|
||||
@endpush
|
||||
34
resources/views/vendor/crud-policies/crud/modules/sorter.blade.php
vendored
Normal file
34
resources/views/vendor/crud-policies/crud/modules/sorter.blade.php
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<tr>
|
||||
@foreach ($modelClass::getEditableProperties() as $colname => $prop)
|
||||
@php
|
||||
$sortParams = ['sort_col' => $colname];
|
||||
$sortParams = request()->search ?
|
||||
array_merge($sortParams, ['search' => request()->search]) : $sortParams;
|
||||
@endphp
|
||||
@if(in_array(CrudAction::viewAny(), $prop['actions']))
|
||||
@switch($prop['type'])
|
||||
@case(CrudType::password())
|
||||
{{-- Ignore --}}
|
||||
@break
|
||||
@default
|
||||
<th scope="col">
|
||||
{{ $prop['label'] }}
|
||||
@if(!session("crud.$modelTable.sort_way") or session("crud.$modelTable.sort_col") !== $colname or (session("crud.$modelTable.sort_way") === 'desc' and session("crud.$modelTable.sort_col") === $colname))
|
||||
<a class="col_sort text-secondary lead asc" href="{{ CrudController::getRoutePrefixed("$modelTable.index", array_merge($sortParams, ['sort_way' => 'asc'])) }}"> ↓ </a>
|
||||
@endif
|
||||
@if(!session("crud.$modelTable.sort_way") or session("crud.$modelTable.sort_col") !== $colname or (session("crud.$modelTable.sort_way") === 'asc' and session("crud.$modelTable.sort_col") === $colname))
|
||||
<a class="col_sort text-secondary lead desc" href="{{ CrudController::getRoutePrefixed("$modelTable.index", array_merge($sortParams, ['sort_way' => 'desc'])) }}"> ↑ </a>
|
||||
@endif
|
||||
</th>
|
||||
@endswitch
|
||||
@endif
|
||||
@endforeach
|
||||
<th scope="col">
|
||||
@if(session("crud.$modelTable.sort_way") and session("crud.$modelTable.sort_col"))
|
||||
<a href="{{ request()->fullUrlWithQuery(['sort_col' => '', 'sort_way' => '']) }}" class="btn btn-small btn-danger">⌫</a>
|
||||
@endif
|
||||
</th>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
109
resources/views/vendor/crud-policies/crud/printfield.blade.php
vendored
Normal file
109
resources/views/vendor/crud-policies/crud/printfield.blade.php
vendored
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
@switch($action)
|
||||
@case(CrudAction::viewAny())
|
||||
@switch($props['type'])
|
||||
@case(CrudType::email())
|
||||
<a href="mailto:$field">{{ $field }}</a>
|
||||
@break
|
||||
@case(CrudType::enum())
|
||||
{{ $model->{$fieldName}->label }}
|
||||
@break
|
||||
@case(CrudType::belongsTo())
|
||||
@php
|
||||
$obj = null;
|
||||
$obj = $model->{Str::singular((new $prop['belongsTo']())->getTable())} ??
|
||||
$prop['belongsTo']::find($model->{$fieldName});
|
||||
@endphp
|
||||
{{ $obj->{$model->crudLabelColumn} }}
|
||||
@break
|
||||
@case(CrudType::belongsToMany())
|
||||
{{ $model->{$fieldName}->implode($prop['belongsToManyLabel'], ',') }}
|
||||
@break
|
||||
@case(CrudType::boolean())
|
||||
@if($model->{$fieldName})OUI @else NON @endif
|
||||
@break
|
||||
@case(CrudType::image())
|
||||
<img class="img-responsive" src="{{ sprintf('/storage/%s', $model->{$fieldName}) }}" alt="{{ sprintf('/storage/%s', $model->{$fieldName}) }}">
|
||||
@break
|
||||
@case(CrudType::order())
|
||||
@if(
|
||||
Session::get("crud.$modelTable.sort_col") === $fieldName and
|
||||
Session::get("crud.$modelTable.sort_way") === 'asc'
|
||||
)
|
||||
<span>
|
||||
@if($model->{$fieldName} - 1 >= 0)
|
||||
<form class="d-inline" action="{{ route('crud-policies.models.changeOrder', [
|
||||
'modelTable' => $modelTable,
|
||||
'modelId' => $model->id,
|
||||
'colName' => $fieldName,
|
||||
'newOrder' => $model->{$fieldName} - 1,
|
||||
'oldUrl' => base64_encode(request()->getRequestUri())
|
||||
]) }}" method="POST">
|
||||
@csrf
|
||||
@method('put')
|
||||
<button class="col_sort btn btn-xs btn-primary text-decoration-none fw-bold lead desc">↑</button>
|
||||
</form>
|
||||
|
||||
@else
|
||||
<span class="ms-2 me-3"> </span>
|
||||
@endif
|
||||
{{ $model->{$fieldName} }}
|
||||
@if(${"$modelTable$fieldName"} !== $model->{$fieldName})
|
||||
|
||||
<form class="d-inline" action="{{ route('crud-policies.models.changeOrder', [
|
||||
'modelTable' => $modelTable,
|
||||
'modelId' => $model->id,
|
||||
'colName' => $fieldName,
|
||||
'newOrder' => $model->{$fieldName} + 1,
|
||||
'oldUrl' => base64_encode(request()->getRequestUri())
|
||||
]) }}" method="POST">
|
||||
@csrf
|
||||
@method('put')
|
||||
<button class="col_sort btn btn-xs btn-primary text-decoration-none fw-bold lead asc">↓</button>
|
||||
</form>
|
||||
@else
|
||||
<span class="ms-2 me-3"> </span>
|
||||
@endif
|
||||
</span>
|
||||
@else
|
||||
{{ $model->{$fieldName} }}
|
||||
@endif
|
||||
@break
|
||||
@default
|
||||
{{ $field }}
|
||||
@endswitch
|
||||
@break
|
||||
|
||||
@case(CrudAction::view())
|
||||
@switch($props['type'])
|
||||
@case(CrudType::email())
|
||||
<a href="mailto:$field">{{ $field }}</a>
|
||||
@break
|
||||
@case(CrudType::enum())
|
||||
{{ $model->{$fieldName}->label }}
|
||||
@break
|
||||
@case(CrudType::json())
|
||||
@json($field)
|
||||
@break
|
||||
@case(CrudType::boolean())
|
||||
@if($model->{$fieldName})OUI @else NON @endif
|
||||
@break
|
||||
@case(CrudType::image())
|
||||
<img class="img-responsive" src="{{ sprintf('/storage/%s', $model->{$fieldName}) }}" alt="{{ sprintf('/storage/%s', $model->{$fieldName}) }}">
|
||||
@break
|
||||
@case(CrudType::order())
|
||||
{{ $model->{$fieldName} }}
|
||||
@break
|
||||
@case(CrudType::belongsTo())
|
||||
{{ $prop['belongsTo']::find($model->{$fieldName})->{$model->crudLabelColumn} }}
|
||||
@break
|
||||
@case(CrudType::belongsToMany())
|
||||
{{ $model->{$fieldName}->implode($prop['belongsToManyLabel'], ',') }}
|
||||
@break
|
||||
@default
|
||||
{{ $field }}
|
||||
@endswitch
|
||||
@break
|
||||
|
||||
@default
|
||||
@dd('unknown action')
|
||||
@endswitch
|
||||
61
resources/views/vendor/crud-policies/crud/show.blade.php
vendored
Normal file
61
resources/views/vendor/crud-policies/crud/show.blade.php
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
@extends($viewLayout)
|
||||
|
||||
@section('title', sprintf('%s - %s', transFb(sprintf('models.classes.%s', strtolower(Str::plural(class_basename($modelClass)))), Str::plural(class_basename($modelClass))), __('crud-policies::crud.view')))
|
||||
@section('description', sprintf('%s %s', __('crud-policies::crud.view'), trans(class_basename($modelClass))))
|
||||
@section('metaIndex', 'noindex,nofollow')
|
||||
|
||||
@section('content')
|
||||
<div class="card">
|
||||
@include('crud-policies::crud.modules.flashMessage')
|
||||
<div class="card-header">
|
||||
@can('viewAny', $modelClass)
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.index")}}">{{ transFb(sprintf('models.classes.%s', strtolower(Str::plural(class_basename($modelClass)))), Str::plural(class_basename($modelClass))) }}</a> - {{ __('crud-policies::crud.view') }}
|
||||
@else
|
||||
{{ trans(Str::plural(class_basename($modelClass))) }} - {{ __('crud-policies::crud.show') }}
|
||||
@endcan
|
||||
<div class="btn-group float-end" role="group" aria-label="{{ Str::plural(__('crud-policies::crud.action')) }}">
|
||||
@can('update', $model)
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.edit", $model)}}" class="btn btn-info ">{{ __('crud-policies::crud.update') }}</a>
|
||||
@endcan
|
||||
@can('delete', $model)
|
||||
<form action="{{ CrudController::getRoutePrefixed("$modelTable.destroy", $model)}}" method="POST" onsubmit="__CRUD.confirmDelete(event)">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="btn btn-danger">{{ __('crud-policies::crud.delete') }}</button>
|
||||
</form>
|
||||
@endcan
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<table class="table table-sm table-bordered border-primary align-top table-striped text-center">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
<th scope="col" class="w-25">{{ __('crud-policies::crud.property') }}</th>
|
||||
<th scope="col" class="w-75">{{ __('crud-policies::crud.value') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($modelClass::getEditableProperties() as $fieldName => $prop)
|
||||
@if(in_array(CrudAction::view(), $prop['actions']))
|
||||
@switch($prop['type'])
|
||||
@case(CrudType::password())
|
||||
{{-- Ignore --}}
|
||||
@break
|
||||
@default
|
||||
<tr>
|
||||
<td>{{ $prop['label'] }}</td>
|
||||
<td>@include('crud-policies::crud.printfield', [
|
||||
'action' => CrudAction::view(),
|
||||
'field' => $model->{$fieldName},
|
||||
'props' => $prop
|
||||
])</td>
|
||||
</tr>
|
||||
@endswitch
|
||||
@endif
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@include('crud-policies::crud.modules.scriptConstants')
|
||||
@endsection
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
|
||||
use App\Http\Controllers\FileController;
|
||||
use App\Http\Controllers\LogController;
|
||||
use App\Http\Controllers\LoginController;
|
||||
use App\Http\Controllers\ProjectController;
|
||||
use App\Http\Controllers\SiteController;
|
||||
use App\Http\Controllers\TicketController;
|
||||
use App\Http\Controllers\UserController;
|
||||
|
|
@ -29,8 +32,18 @@ Route::middleware(['auth'])->group(function () {
|
|||
Route::post('/logout', [LoginController::class, 'logout'])->name('logout');
|
||||
// Ticket
|
||||
Route::resource('ticket', TicketController::class)->except(['destroy']);
|
||||
Route::resource('sites', SiteController::class);
|
||||
Route::resource('users', UserController::class);
|
||||
Route::resource('sites', SiteController::class);
|
||||
Route::resource('projects', ProjectController::class);
|
||||
|
||||
// LOGS and Files
|
||||
Route::resource('logs', LogController::class);
|
||||
Route::resource('files', FileController::class);
|
||||
Route::resource('projects.logs', LogController::class);
|
||||
Route::resource('projects.files', FileController::class);
|
||||
Route::resource('sites.logs', LogController::class);
|
||||
Route::resource('sites.files', FileController::class);
|
||||
|
||||
Route::prefix('/ticket')->name('ticket.')->group(function () {
|
||||
Route::post('/{ticket}/status', [TicketController::class, 'changeStatus'])
|
||||
->middleware('can:changeStatus,ticket')
|
||||
|
|
@ -45,8 +58,4 @@ Route::middleware(['auth'])->group(function () {
|
|||
->middleware('can:createMessage,ticket')
|
||||
->name('message.create');
|
||||
});
|
||||
// Projets
|
||||
Route::middleware(['is-admin'])->group(function () {
|
||||
Route::resource('site', SiteController::class)->except('show');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue