mirror of https://github.com/4xmen/xshop.git
added clip controller
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**/
|
||||
}
|
@ -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'],
|
||||
];
|
||||
}
|
||||
}
|
@ -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> </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
|
Loading…
Reference in New Issue