96 lines
3.1 KiB
PHP
96 lines
3.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Services\Admin;
|
||
|
|
|
||
|
|
use App\Models\ManageShortClips;
|
||
|
|
use File;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use Illuminate\Support\Facades\Validator;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Class ManageShortClipsService.
|
||
|
|
*/
|
||
|
|
class ManageShortClipsService {
|
||
|
|
|
||
|
|
public function insert_short_clips(Request $request) {
|
||
|
|
|
||
|
|
// for image upload start
|
||
|
|
$rules = [
|
||
|
|
'thumbnail' => 'required|file|max:400', // 400 KB
|
||
|
|
];
|
||
|
|
|
||
|
|
$validator = Validator::make($request->all(),$rules);
|
||
|
|
|
||
|
|
if ($validator->fails()) {
|
||
|
|
if ($request->expectsJson()) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
$file = $request->file('thumbnail');
|
||
|
|
$ext = $file->extension();
|
||
|
|
$file_name = time().'.'.$ext;
|
||
|
|
$path = public_path().'/uploads/short_clips';
|
||
|
|
$file-> move($path,$file_name);
|
||
|
|
}
|
||
|
|
|
||
|
|
// for image upload end
|
||
|
|
$insertShortsClips = new ManageShortClips;
|
||
|
|
$insertShortsClips->video_title = $request->input('video_title');
|
||
|
|
$insertShortsClips->video_description = $request->input('description');
|
||
|
|
$insertShortsClips->video_url = $request->input('video_url');
|
||
|
|
$insertShortsClips->thumbnail = $file_name;
|
||
|
|
$insertShortsClips->save();
|
||
|
|
return $insertShortsClips;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function get_all_short_clips() {
|
||
|
|
$data = [
|
||
|
|
'getAllShortsClips' => $getAllShortsClips = ManageShortClips::latest()->get(),
|
||
|
|
'getAllShortsClipsDeleted' => $getAllShortsClipsDeleted = ManageShortClips::onlyTrashed()->orderBy('deleted_at', 'desc')->get()
|
||
|
|
];
|
||
|
|
return $data;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function edit_short_clips($id) {
|
||
|
|
$editShortClips = ManageShortClips::find($id);
|
||
|
|
// echo "<pre>"; print_r($editShortClips); exit;
|
||
|
|
return $editShortClips;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function update_short_clips(Request $request) {
|
||
|
|
// dd($request);
|
||
|
|
$shortClipsId = $request->edit_id;
|
||
|
|
$updateShortClips = ManageShortClips::find($request->edit_id);
|
||
|
|
if($request->thumbnail){
|
||
|
|
$rules = [
|
||
|
|
'thumbnail' => 'required|file|max:400', // 400 KB
|
||
|
|
];
|
||
|
|
|
||
|
|
$validator = Validator::make($request->all(),$rules);
|
||
|
|
|
||
|
|
if ($validator->fails()) {
|
||
|
|
if ($request->expectsJson()) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
$file_one = $request->file('thumbnail');
|
||
|
|
$ext = $file_one->extension();
|
||
|
|
$file_name_main_image = time() . '.' . $ext;
|
||
|
|
$path = public_path() . '/uploads/short_clips';
|
||
|
|
$file_one->move($path, $file_name_main_image);
|
||
|
|
$updateShortClips->thumbnail = $file_name_main_image;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$updateShortClips->video_title = $request->input('video_title');
|
||
|
|
$updateShortClips->video_description = $request->input('description');
|
||
|
|
$updateShortClips->video_url = $request->input('video_url');
|
||
|
|
|
||
|
|
$updateShortClips->save();
|
||
|
|
return $updateShortClips;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|