Skip to content

Commit

Permalink
add uuid trait and dropzone component blade aliase
Browse files Browse the repository at this point in the history
  • Loading branch information
guysolamour committed Feb 6, 2022
1 parent 727de93 commit 4adfbe6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
14 changes: 6 additions & 8 deletions resources/views/components/components/dropzone.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@props([
'collection', 'message', 'label', 'model', 'maxFiles', 'key', 'paramName', 'uploadMultiple',
'maxFileSize', 'addRemoveLinks', 'formName'
'collection', 'message', 'label', 'model', 'key', 'paramName', 'uploadMultiple',
'maxFileSize', 'addRemoveLinks', 'formName', 'createImageThumbnails'
])

@php
Expand All @@ -12,13 +12,11 @@
$model_classname = base64_encode(is_object($model) ? get_class($model) : (string) $model);
if (!isset($formName)){
$formName = $model->form_name ;
}
$formName = $formName ?? $model->form_name ;
$collection ??= config('administrable.media.collections.images.label');
$collection = $collection ?? config('administrable.media.collections.images.label');
if (!isset($key) && is_object($model) && method_exists($model, 'getKey')){
if (empty($key) && is_object($model) && method_exists($model, 'getKey')){
$key = $model->getKey();
}
Expand Down Expand Up @@ -160,7 +158,7 @@ function dropzoneEditMode(){
paramName: @json($paramName ?? 'file'), // The name that will be used to transfer the file
uploadMultiple: @json($uploadMultiple ?? true),
method: 'POST',
headers:{'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
headers:{'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content},
parallelUploads: 1,
maxFilesize: @json($maxFileSize ?? 10),
previewTemplate: document.querySelector('#{{ $selector }}').innerHTML,
Expand Down
16 changes: 16 additions & 0 deletions resources/views/components/helpers/dropzone.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@



<x-administrable::dropzone
:collection="$collection ?? null"
:message="$message ?? null"
:label="$label ?? null"
:model="$model"
:key="$key ?? null"
:paramName="$paramName ?? null"
:uploadMultiple="$uploadMultiple ?? null"
:maxFileSize="$maxFileSize ?? null"
:addRemoveLinks="$addRemoveLinks ?? null"
:formName="$formName ?? null"
:createImageThumbnails="$createImageThumbnails ?? null"
/>
2 changes: 1 addition & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Guysolamour\Administrable\Console\Administrable\UpdateGuardCommand;
use Guysolamour\Administrable\Console\Administrable\AdminInstallCommand;
use Guysolamour\Administrable\Console\Administrable\GenerateFrontDashboardCommand;
use phpDocumentor\Reflection\Types\Static_;

class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
Expand Down Expand Up @@ -91,6 +90,7 @@ public function boot()
Blade::include('administrable::helpers.includeback', 'includeback');
Blade::include('administrable::helpers.includefront', 'includefront');
Blade::include('administrable::helpers.deleteall', 'deleteall');
Blade::include('administrable::helpers.dropzone', 'dropzone');

$this->loadPolicies([
config('administrable.modules.comment.model') => config('administrable.modules.comment.front.policy'),
Expand Down
29 changes: 29 additions & 0 deletions src/Traits/HasUuid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Guysolamour\Administrable\Traits;

use Illuminate\Support\Str;


trait HasUuid
{
public static function bootHasUuid()
{
/**
* @param \Illuminate\Database\Eloquent\Model|HasUuid $model
*/
static::saving(function ($model) {
$model->setAttribute($model->getUuidFieldName(), Str::uuid());
});
}

public function getUuidFieldName() :string
{
return 'uuid';
}

public function getRouteKeyName(): string
{
return $this->getUuidFieldName();
}
}

0 comments on commit 4adfbe6

Please sign in to comment.