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)) +