diff --git a/app/Http/Controllers/Admin/AttachmentController.php b/app/Http/Controllers/Admin/AttachmentController.php index 0630ddd..1e8aa4a 100644 --- a/app/Http/Controllers/Admin/AttachmentController.php +++ b/app/Http/Controllers/Admin/AttachmentController.php @@ -115,6 +115,16 @@ class AttachmentController extends XController { return parent::delete($item); } + public function deattach(Attachment $item) + { + $item->attachable_id = null; + $item->attachable_type = null; + $item->save(); + + logAdmin(__METHOD__,__CLASS__,$item->id); + return redirect()->back() + ->with(['message' => __('As you wished deattached successfully')]); + } public function update(Request $request, Attachment $item) diff --git a/app/Models/Attachment.php b/app/Models/Attachment.php index f746e47..1b98882 100644 --- a/app/Models/Attachment.php +++ b/app/Models/Attachment.php @@ -37,4 +37,24 @@ class Attachment extends Model return \Storage::url('attachments/' . $this->file); } + + + public function ownerModel(){ + switch ($this->attachable_type){ + case Product::class: + return Product::whereId($this->attachable_id)->first(); + case Post::class: + return Post::whereId($this->attachable_id)->first(); + case Group::class: + return Group::whereId($this->attachable_id)->first(); + case Category::class: + return Category::whereId($this->attachable_id)->first(); + case Clip::class: + return Clip::whereId($this->attachable_id)->first(); + case Gallery::class: + return Gallery::whereId($this->attachable_id)->first(); + default: + return null; + } + } } diff --git a/app/Models/Category.php b/app/Models/Category.php index a6baf37..978c0d9 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -50,4 +50,8 @@ class Category extends Model return $this->belongsToMany(Prop::class); } + public function attachs(){ + return $this->morphMany(Attachment::class,'attachable'); + } + } diff --git a/app/Models/Clip.php b/app/Models/Clip.php index a916fc5..caacafb 100644 --- a/app/Models/Clip.php +++ b/app/Models/Clip.php @@ -41,4 +41,10 @@ class Clip extends Model { return $this->belongsTo(\App\Models\User::class); } + + public function attachs(){ + return $this->morphMany(Attachment::class,'attachable'); + } + + } diff --git a/app/Models/Gallery.php b/app/Models/Gallery.php index f61f54a..8082e99 100644 --- a/app/Models/Gallery.php +++ b/app/Models/Gallery.php @@ -59,4 +59,8 @@ class Gallery extends Model implements HasMedia { return $this->belongsTo(\App\Models\User::class); } + + public function attachs(){ + return $this->morphMany(Attachment::class,'attachable'); + } } diff --git a/app/Models/Group.php b/app/Models/Group.php index 2262c62..afaa267 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -55,4 +55,8 @@ class Group extends Model return \Storage::url('groups/' . $this->bg); } + + public function attachs(){ + return $this->morphMany(Attachment::class,'attachable'); + } } diff --git a/app/Models/Post.php b/app/Models/Post.php index 6934c27..05d7997 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -97,6 +97,10 @@ class Post extends Model implements HasMedia return $this->belongsTo(Group::class); } + public function attachs(){ + return $this->morphMany(Attachment::class,'attachable'); + } + // public function toArray() // { diff --git a/app/Models/Product.php b/app/Models/Product.php index f3c7e81..c7803b9 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -21,6 +21,9 @@ class Product extends Model implements HasMedia 'qidz' => 'array' ]; + public function attachs(){ + return $this->morphMany(Attachment::class,'attachable'); + } protected $guarded = []; diff --git a/resources/views/admin/categories/category-form.blade.php b/resources/views/admin/categories/category-form.blade.php index f224b6b..1c6fa58 100644 --- a/resources/views/admin/categories/category-form.blade.php +++ b/resources/views/admin/categories/category-form.blade.php @@ -43,6 +43,14 @@ @endif + @if(isset($item)) +
+
+ @include('components.panel-attachs',['attachs' => $item->attachs]) +
+
+ @endif +
diff --git a/resources/views/admin/clips/clip-form.blade.php b/resources/views/admin/clips/clip-form.blade.php index 7871e14..6ace078 100644 --- a/resources/views/admin/clips/clip-form.blade.php +++ b/resources/views/admin/clips/clip-form.blade.php @@ -38,6 +38,13 @@
@endif + @if(isset($item)) +
+
+ @include('components.panel-attachs',['attachs' => $item->attachs]) +
+
+ @endif
diff --git a/resources/views/admin/galleries/gallery-form.blade.php b/resources/views/admin/galleries/gallery-form.blade.php index 1f850e0..724385a 100644 --- a/resources/views/admin/galleries/gallery-form.blade.php +++ b/resources/views/admin/galleries/gallery-form.blade.php @@ -41,6 +41,14 @@
@endif + @if(isset($item)) +
+
+ @include('components.panel-attachs',['attachs' => $item->attachs]) +
+
+ @endif +
diff --git a/resources/views/admin/groups/group-form.blade.php b/resources/views/admin/groups/group-form.blade.php index 5649199..28c2c54 100644 --- a/resources/views/admin/groups/group-form.blade.php +++ b/resources/views/admin/groups/group-form.blade.php @@ -42,6 +42,14 @@
@endif + @if(isset($item)) +
+
+ @include('components.panel-attachs',['attachs' => $item->attachs]) +
+
+ @endif +
diff --git a/resources/views/admin/posts/post-form.blade.php b/resources/views/admin/posts/post-form.blade.php index 5403559..2629391 100644 --- a/resources/views/admin/posts/post-form.blade.php +++ b/resources/views/admin/posts/post-form.blade.php @@ -72,6 +72,13 @@
+ @if(isset($item)) +
+
+ @include('components.panel-attachs',['attachs' => $item->attachs]) +
+
+ @endif
diff --git a/resources/views/admin/products/product-form.blade.php b/resources/views/admin/products/product-form.blade.php index 6a22ffd..16bef69 100644 --- a/resources/views/admin/products/product-form.blade.php +++ b/resources/views/admin/products/product-form.blade.php @@ -76,6 +76,7 @@ + @include('components.err')
diff --git a/resources/views/admin/products/sub-pages/product-step1.blade.php b/resources/views/admin/products/sub-pages/product-step1.blade.php index f84b377..2af7f00 100644 --- a/resources/views/admin/products/sub-pages/product-step1.blade.php +++ b/resources/views/admin/products/sub-pages/product-step1.blade.php @@ -1,118 +1,119 @@ -
-
-
- - -
+
+
+
+ +
-
-
- - -
+
+
+
+ +
+
-
-
- +
+
+ - -
+
-
-
- +
+
+
+ - -
+
-
-
- +
+
+
+ -{{-- data-url="{{route('props.list','')}}/"--}} - category_id??null)}}' - :close-on-Select="true"> -
+ {{-- data-url="{{route('props.list','')}}/"--}} + category_id??null)}}' + :close-on-Select="true">
-
-
- - -
+
+
+
+ +
-
-
- - -
+
+
+
+ +
-
-
- - -
+
+
+
+ +
-
-
- - -
+
+
+
+ +
+
diff --git a/resources/views/admin/products/sub-pages/product-step3.blade.php b/resources/views/admin/products/sub-pages/product-step3.blade.php index a73d49f..3c7d274 100644 --- a/resources/views/admin/products/sub-pages/product-step3.blade.php +++ b/resources/views/admin/products/sub-pages/product-step3.blade.php @@ -175,3 +175,7 @@ {{--
--}} {{--
--}} +
+
+ @include('components.panel-attachs',['attachs' => $item->attachs]) +
diff --git a/resources/views/components/panel-attachs.blade.php b/resources/views/components/panel-attachs.blade.php new file mode 100644 index 0000000..93c5224 --- /dev/null +++ b/resources/views/components/panel-attachs.blade.php @@ -0,0 +1,28 @@ +

+ {{__("Attachments")}} + + + + +

+
+
    + @foreach($attachs as $attach) + +
  • + + + +
    + + + {{$attach->file}} + + [ {{formatFileSize($attach->size)}} ] + [ {{$attach->ext}} ] +
    + +
  • + @endforeach +
diff --git a/routes/web.php b/routes/web.php index 77f42a2..6b0d6c0 100644 --- a/routes/web.php +++ b/routes/web.php @@ -113,6 +113,7 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group( Route::get('edit/{item}', [\App\Http\Controllers\Admin\AttachmentController::class, 'edit'])->name('edit'); Route::post('update/{item}', [\App\Http\Controllers\Admin\AttachmentController::class, 'update'])->name('update'); Route::get('delete/{item}', [\App\Http\Controllers\Admin\AttachmentController::class, 'destroy'])->name('destroy'); + Route::get('deattach/{item}', [\App\Http\Controllers\Admin\AttachmentController::class, 'deattach'])->name('deattach'); Route::post('bulk', [\App\Http\Controllers\Admin\AttachmentController::class, "bulk"])->name('bulk'); }); Route::prefix('clips')->name('clip.')->group(