Spaces:
Running
Running
File size: 4,771 Bytes
40dca3b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | <?php
namespace App\Http\Controllers\WebControllers\V1\Backend;
use App\Http\Controllers\BaseController;
use App\Services\ChapterServices;
use App\Services\ComicServices;
use App\Services\HashtagServices;
use Google_Service_Drive_DriveFile;
use Google_Service_Drive_Permission;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use App\Http\Requests\ComicRequest;
class ComicController extends BaseController
{
private $comicService;
private $chapterServices;
private $hashtagServices;
public function __construct(ComicServices $comicService,
ChapterServices $chapterServices,
HashtagServices $hashtagServices)
{
$this->hashtagServices = $hashtagServices;
$this->chapterServices = $chapterServices;
$this->comicService = $comicService;
parent::__construct();
}
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
$request['isBackend'] = true;
$request['loading_hashtag']= true;
$request['loading_tagged']= true;
$comics = $this->comicService->index($request);
$comics = $this->comicService->prepareHashtags($comics);
$param = ($request->except(['page']));
return view('Backend.pages.comics.list', compact('comics','param'));
}
/**
* Show the form for creating a new resource.
*/
public function create(Request $request)
{
$hashtags = $this->hashtagServices->index($request);
return view('Backend.pages.comics.add',compact('hashtags'));
}
/**
* Store a newly created resource in storage.
*/
public function store(ComicRequest $request)
{
$comic = $request->only([
'comic_name',
'bg_color',
'tranfer_color',
'summary_contents',
'tagged'
]);
try {
$this->comicService->uploadGGDrive($request,$comic);
}catch (\Exception $e){
$request->session()->flash('msgFail', $e->getMessage());
return back()->with(['comic' => $comic]);
}
DB::beginTransaction();
try {
$result = $this->comicService->save($comic);
DB::commit();
$request->session()->flash('msgSuccess', trans('comic.msg_content.msg_add_success'));
return redirect()->route('comics.edit', ['code' => $result->comic_code]);
} catch (\Exception $e) {
DB::rollback();
$request->session()->flash('msgFail', $e->getMessage());
return back()->with(['comic' => $comic]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Request $request,string $id)
{
$comic = $this->comicService->show($id);
$chapters = $this->chapterServices->findByComics($request,$comic->id);
$param= $request->except(['page']);
$hashtags = $this->hashtagServices->index($request);
return view('Backend.pages.comics.edit', compact('comic','chapters','param','hashtags'));
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
$comic = $request->only([
'comic_name',
'bg_color',
'tranfer_color',
'summary_contents',
'tagged'
]);
$comic['comic_code'] = $id;
try {
$this->comicService->uploadGGDrive($request,$comic);
}catch (\Exception $e){
$request->session()->flash('msgFail', $e->getMessage());
return back()->with(['comic' => $comic]);
}
DB::beginTransaction();
try {
$result = $this->comicService->save($comic);
DB::commit();
$request->session()->flash('msgSuccess', trans('comic.msg_content.msg_edit_success'));
return redirect()->route('comics.edit', ['code' => $result->comic_code]);
} catch (\Exception $e) {
DB::rollback();
$request->session()->flash('msgFail', $e->getMessage());
return back()->with(['comic' => $comic]);
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Request $request, string $id)
{
$result = $this->comicService->delete($id);
if (!$result) {
$request->session()->flash('msgFail', trans('comic.msg_content.msg_delete_fail'));
}
return redirect()->route('comics.list') ;
}
}
|