added attachment relations

added deattach
pull/44/head
A1Gard 5 months ago
parent 56acb26137
commit 84ad1c1584

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

@ -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;
}
}
}

@ -50,4 +50,8 @@ class Category extends Model
return $this->belongsToMany(Prop::class);
}
public function attachs(){
return $this->morphMany(Attachment::class,'attachable');
}
}

@ -41,4 +41,10 @@ class Clip extends Model
{
return $this->belongsTo(\App\Models\User::class);
}
public function attachs(){
return $this->morphMany(Attachment::class,'attachable');
}
}

@ -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');
}
}

@ -55,4 +55,8 @@ class Group extends Model
return \Storage::url('groups/' . $this->bg);
}
public function attachs(){
return $this->morphMany(Attachment::class,'attachable');
}
}

@ -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()
// {

@ -21,6 +21,9 @@ class Product extends Model implements HasMedia
'qidz' => 'array'
];
public function attachs(){
return $this->morphMany(Attachment::class,'attachable');
}
protected $guarded = [];

@ -43,6 +43,14 @@
</div>
@endif
@if(isset($item))
<div class="item-list mb-3">
<div class="p-3">
@include('components.panel-attachs',['attachs' => $item->attachs])
</div>
</div>
@endif
</div>
<div class="col-lg-9 ps-xl-1 ps-xxl-1">
<div class="general-form ">

@ -38,6 +38,13 @@
</div>
</div>
@endif
@if(isset($item))
<div class="item-list mb-3">
<div class="p-3">
@include('components.panel-attachs',['attachs' => $item->attachs])
</div>
</div>
@endif
</div>
<div class="col-lg-9 ps-xl-1 ps-xxl-1">

@ -41,6 +41,14 @@
</div>
@endif
@if(isset($item))
<div class="item-list mb-3">
<div class="p-3">
@include('components.panel-attachs',['attachs' => $item->attachs])
</div>
</div>
@endif
</div>
<div class="col-lg-9 ps-xl-1 ps-xxl-1">
<div class="general-form ">

@ -42,6 +42,14 @@
</div>
@endif
@if(isset($item))
<div class="item-list mb-3">
<div class="p-3">
@include('components.panel-attachs',['attachs' => $item->attachs])
</div>
</div>
@endif
</div>
<div class="col-lg-9 ps-xl-1 ps-xxl-1">

@ -72,6 +72,13 @@
<remix-icon-picker xname="icon" xvalue="{{old('icon',$item->icon??null)}}"></remix-icon-picker>
</div>
</div>
@if(isset($item))
<div class="item-list mb-3">
<div class="p-3">
@include('components.panel-attachs',['attachs' => $item->attachs])
</div>
</div>
@endif
</div>
<div class="col-lg-9 ps-xl-1 ps-xxl-1">

@ -76,6 +76,7 @@
<i class="ri-save-3-line"></i>
</li>
</ul>
@include('components.err')
<div id="step-tabs">
<div id="step1">
<div class="card">

@ -1,4 +1,4 @@
<div class="row">
<div class="row">
<div class="col-md-6 mt-3">
<div class="form-group">
<label for="name">
@ -32,7 +32,8 @@
</label>
<currency-input xname="price" xid="price" @error('price')
:err="true" @enderror xtitle="{{__('Base price')}}" :xvalue="{{old('price',$item->price??null)}}"></currency-input>
:err="true" @enderror xtitle="{{__('Base price')}}"
:xvalue="{{old('price',$item->price??null)}}"></currency-input>
</div>
</div>
<div class="col-lg-6 mt-3">
@ -51,7 +52,7 @@
{{__('Main product category')}}
</label>
{{-- data-url="{{route('props.list','')}}/"--}}
{{-- data-url="{{route('props.list','')}}/"--}}
<searchable-select
vuex-dispatch="updateCategory"
@error('category_id') :err="true" @enderror
@ -115,4 +116,4 @@
rows="8">{{old('description',$item->description??null)}}</textarea>
</div>
</div>
</div>
</div>

@ -175,3 +175,7 @@
{{-- </div>--}}
{{--</div>--}}
<hr>
<div class="mt-4">
@include('components.panel-attachs',['attachs' => $item->attachs])
</div>

@ -0,0 +1,28 @@
<h4>
{{__("Attachments")}}
<a href="{{route('admin.attachment.create')}}?" class="btn btn-light float-end mb-2">
<i class="ri-add-line"></i>
<i class="ri-attachment-line"></i>
</a>
</h4>
<div class="clearfix"></div>
<ul class="list-group">
@foreach($attachs as $attach)
<li class="list-group-item">
<a href="{{route('admin.attachment.deattach',$attach->slug)}}" class="btn btn-danger float-end btn-sm" data-bs-toggle="tooltip" data-bs-placement="auto" data-bs-custom-class="custom-tooltip"
data-bs-title="{{__("Deattach")}}">
<i class="ri-close-line"></i>
</a>
<div class="p-2">
<a href="{{$attach->url()}}">
{{$attach->file}}
</a>
[ {{formatFileSize($attach->size)}} ]
[ {{$attach->ext}} ]
</div>
</li>
@endforeach
</ul>

@ -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(

Loading…
Cancel
Save