added clip controller

pull/44/head
A1Gard 6 months ago
parent 05f5fc05f2
commit 0c6148c84d

@ -0,0 +1,155 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Controllers\XController;
use App\Http\Requests\ClipSaveRequest;
use App\Models\Access;
use App\Models\Clip;
use Illuminate\Http\Request;
use App\Helper;
use function App\Helpers\hasCreateRoute;
class ClipController extends XController
{
// protected $_MODEL_ = Clip::class;
// protected $SAVE_REQUEST = ClipSaveRequest::class;
protected $cols = ['title','status'];
protected $extra_cols = ['id','slug','cover'];
protected $searchable = ['title','body'];
protected $listView = 'admin.clips.clip-list';
protected $formView = 'admin.clips.clip-form';
protected $buttons = [
'edit' =>
['title' => "Edit", 'class' => 'btn-outline-primary', 'icon' => 'ri-edit-2-line'],
'show' =>
['title' => "Detail", 'class' => 'btn-outline-light', 'icon' => 'ri-eye-line'],
'destroy' =>
['title' => "Remove", 'class' => 'btn-outline-danger delete-confirm', 'icon' => 'ri-close-line'],
];
public function __construct()
{
parent::__construct(Clip::class, ClipSaveRequest::class);
}
/**
* @param $clip Clip
* @param $request ClipSaveRequest
* @return Clip
*/
public function save($clip, $request)
{
$clip->title = $request->input('title');
$clip->slug = $this->getSlug($clip,'slug','title');
$clip->body = $request->input('body');
$clip->user_id = auth()->id();
$clip->status = $request->input('status');
// if ($request->hasFile('clip')) {
// $name = $clip->slug . '.' . request()->clip->getClientOriginalExtension();
// $clip->file = $name;
// $request->file('clip')->storeAs('public/clips', $name);
// }
// if ($request->hasFile('cover')) {
// $name = $clip->slug . '.' . request()->cover->getClientOriginalExtension();
// $clip->cover = $name;
// $request->file('cover')->storeAs('public/clips', $name);
// }
if ($request->has('cover')){
$clip->cover = $this->storeFile('cover',$clip, 'clips');
}
if ($request->has('clip')){
$clip->file = $this->storeFile('clip',$clip, 'clips');
}
$clip->save();
$tags = array_filter(explode(',,', $request->input('tags')));
if (count($tags) > 0){
$clip->syncTags($tags);
}
return $clip;
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
return view($this->formView);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Clip $item)
{
//
return view($this->formView, compact('item'));
}
public function bulk(Request $request)
{
// dd($request->all());
$data = explode('.', $request->input('action'));
$action = $data[0];
$ids = $request->input('id');
switch ($action) {
case 'delete':
$msg = __(':COUNT items deleted successfully', ['COUNT' => count($ids)]);
$this->_MODEL_::destroy($ids);
break;
/**restore*/
case 'restore':
$msg = __(':COUNT items restored successfully', ['COUNT' => count($ids)]);
foreach ($ids as $id) {
$this->_MODEL_::withTrashed()->find($id)->restore();
}
break;
/*restore**/
case 'publish':
$this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 1]);
$msg = __(':COUNT items published successfully', ['COUNT' => count($ids)]);
break;
case 'draft':
$this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 0]);
$msg = __(':COUNT items drafted successfully', ['COUNT' => count($ids)]);
break;
default:
$msg = __('Unknown bulk action : :ACTION', ["ACTION" => $action]);
}
return $this->do_bulk($msg, $action, $ids);
}
public function destroy(Clip $item)
{
return parent::delete($item);
}
public function update(Request $request, Clip $item)
{
return $this->bringUp($request, $item);
}
/**restore*/
public function restore($item)
{
return parent::restoreing(Clip::withTrashed()->where('id', $item)->first());
}
/*restore**/
}

@ -18,7 +18,7 @@ class GroupController extends XController
// protected $SAVE_REQUEST = GroupSaveRequest::class;
protected $cols = ['name','subtitle','parent_id'];
protected $extra_cols = ['id','slug'];
protected $extra_cols = ['id','slug','image'];
protected $searchable = ['name','subtitle','description'];

@ -0,0 +1,32 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ClipSaveRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return auth()->check();
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'title' => ['required', 'string', 'max:255','min:5'],
'body' => ['nullable', 'string',],
'active' => ['nullable', 'boolean'],
'clip' => ['nullable', 'mimes:mp4', 'max:15728640'],
'cover' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,svg', 'max:2048'],
];
}
}

@ -5,11 +5,12 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Tags\HasTags;
use Spatie\Translatable\HasTranslations;
class Clip extends Model
{
use HasFactory, SoftDeletes, HasTranslations;
use HasFactory, SoftDeletes, HasTranslations,HasTags;
public $translatable = ['title','body'];
@ -18,10 +19,10 @@ class Clip extends Model
return 'slug';
}
public function coverUrl()
public function imgUrl()
{
if ($this->cover == null) {
return null;
return asset('assets/upload/logo.svg');;
}
return \Storage::url('clips/' . $this->cover);

@ -51,7 +51,7 @@ class Gallery extends Model implements HasMedia
if ($this->getMedia()->count() > 0) {
return $this->getMedia()->first()->getUrl('gthumb');
} else {
return "no image";
return asset('assets/upload/logo.svg');
}
}

@ -19,7 +19,7 @@ return new class extends Migration
$table->string('file', 2048)->nullable();
$table->string('cover', 2048)->nullable();
$table->unsignedBigInteger('user_id');
$table->boolean('active')->default(true);
$table->unsignedTinyInteger('status')->default(0);
$table->softDeletes();
$table->timestamps();
$table->foreign('user_id')

@ -17,7 +17,7 @@ return new class extends Migration
$table->string('image');
$table->string('tag')->nullable();
$table->unsignedBigInteger('user_id');
$table->boolean('active')->default(true);
$table->unsignedTinyInteger('status')->default(0);
$table->json('data');
$table->timestamps();
$table->foreign('user_id')

@ -0,0 +1,138 @@
@extends('admin.templates.panel-form-template')
@section('title')
@if(isset($item))
{{__("Edit clip")}} [{{$item->title}}]
@else
{{__("Add new clip")}}
@endif -
@endsection
@section('form')
<div class="row">
<div class="col-lg-3">
@include('components.err')
<div class="item-list mb-3">
<h3 class="p-3">
<i class="ri-message-3-line"></i>
{{__("Tips")}}
</h3>
<ul>
<li>
{{__("Add cover to better results")}}
</li>
<li>
{{__("You can create / edit clip as draft, publish it when you want")}}
</li>
</ul>
</div>
@if(isset($item))
<div class="item-list mb-3">
<h3 class="p-3">
<i class="ri-message-3-line"></i>
{{__("Preview")}}
</h3>
<div class="p-2">
<video src="{{$item->fileUrl()}}" poster="{{$item->imgUrl()}}" controls
style="max-width: 100%"></video>
</div>
</div>
@endif
</div>
<div class="col-lg-9 ps-xl-1 ps-xxl-1">
<div class="general-form ">
<h1>
@if(isset($item))
{{__("Edit clip")}} [{{$item->title}}]
@else
{{__("Add new clip")}}
@endif
</h1>
<div class="row">
<div class="col-md-12 mt-3">
<div class="form-group">
<label for="title">
{{__('Title')}}
</label>
<input name="title" type="text" class="form-control @error('title') is-invalid @enderror"
placeholder="{{__('Title')}}" value="{{old('title',$item->title??null)}}"/>
</div>
</div>
<div class="col-md-12 mt-3">
<label for="slug">
{{__('Slug')}}
</label>
<input name="slug" type="text" class="form-control @error('slug') is-invalid @enderror"
placeholder="{{__('Slug')}}" value="{{old('slug',$item->slug??null)}}"/>
</div>
<div class="col-md-12 mt-3">
<div class="form-group">
<label for="body">
{{__('Description')}}
</label>
<textarea name="body" class="ckeditorx form-control @error('body') is-invalid @enderror"
placeholder="{{__('Description')}}">{{old('body',$item->body??null)}}</textarea>
</div>
</div>
<div class="col-md-12 mt-3">
<div class="form-group">
<label>
{{__("Tags")}}
</label>
<tag-input xname="tags" splitter=",,"
xtitle="{{__("Tags, Press enter")}}"
@if(isset($item))
xvalue="{{old('title',implode(',,',$item->tags->pluck('name')->toArray()??''))}}"
@endif
></tag-input>
</div>
</div>
<div class="col-md-4 mt-3">
<div class="form-group">
<label for="status">
{{__('Status')}}
</label>
<select name="status" id="status"
class="form-control @error('status') is-invalid @enderror">
<option value="1"
@if (old('status',$item->status??null) == '1' ) selected @endif >{{__("Published")}} </option>
<option value="0"
@if (old('status',$item->status??null) == '0' ) selected @endif >{{__("Draft")}} </option>
</select>
</div>
</div>
<div class="col-md-4 mt-3">
<div class="form-group">
<label for="cover">
{{__('Cover')}}
</label>
<input name="cover" id="cover" type="file"
class="form-control @error('cover') is-invalid @enderror"
placeholder="{{__('Cover')}}" accept="image/*"/>
</div>
</div>
<div class="col-md-4 mt-3">
<div class="form-group">
<label for="clip">
{{__('Video clip')}}
</label>
<input name="clip" id="clip" type="file"
class="form-control @error('clip') is-invalid @enderror"
placeholder="{{__('Video clip')}}" accept=".mp4"/>
</div>
</div>
<div class="col-md-12">
<label> &nbsp;</label>
<input name="" type="submit" class="btn btn-primary mt-2" value="{{__('Save')}}"/>
</div>
</div>
</div>
</div>
</div>
@endsection

@ -0,0 +1,15 @@
@extends('admin.templates.panel-list-template')
@section('list-title')
<i class="ri-user-3-line"></i>
{{__("Clips list")}}
@endsection
@section('title')
{{__("Clips list")}} -
@endsection
@section('filter')
{{-- Other filters --}}
@endsection
@section('bulk')
{{-- <option value="-"> - </option> --}}
@endsection

@ -97,7 +97,7 @@
</a>
</li>
<li>
<a>
<a href="{{route('admin.clip.index')}}">
<i class="ri-video-fill"></i>
{{__("Video clips")}}
</a>

@ -65,6 +65,19 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group(
Route::post('bulk', [\App\Http\Controllers\Admin\PostController::class, "bulk"])->name('bulk');
Route::get('trashed', [\App\Http\Controllers\Admin\PostController::class, "trashed"])->name('trashed');
});
Route::prefix('clips')->name('clip.')->group(
function () {
Route::get('', [\App\Http\Controllers\Admin\ClipController::class, 'index'])->name('index');
Route::get('create', [\App\Http\Controllers\Admin\ClipController::class, 'create'])->name('create');
Route::post('store', [\App\Http\Controllers\Admin\ClipController::class, 'store'])->name('store');
Route::get('show/{item}', [\App\Http\Controllers\Admin\ClipController::class, 'show'])->name('show');
Route::get('edit/{item}', [\App\Http\Controllers\Admin\ClipController::class, 'edit'])->name('edit');
Route::post('update/{item}', [\App\Http\Controllers\Admin\ClipController::class, 'update'])->name('update');
Route::get('delete/{item}', [\App\Http\Controllers\Admin\ClipController::class, 'destroy'])->name('destroy');
Route::get('restore/{item}', [\App\Http\Controllers\Admin\ClipController::class, 'restore'])->name('restore');
Route::post('bulk', [\App\Http\Controllers\Admin\ClipController::class, "bulk"])->name('bulk');
Route::get('trashed', [\App\Http\Controllers\Admin\ClipController::class, "trashed"])->name('trashed');
});
Route::prefix('galleries')->name('gallery.')->group(
function () {
Route::get('', [\App\Http\Controllers\Admin\GalleryController::class, 'index'])->name('index');

Loading…
Cancel
Save