관리-도구
편집 파일: ReportAnnualController.php
<?php namespace App\Http\Controllers; use Illuminate\Support\Str; use App\Models\ReportAnnual; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class ReportAnnualController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ protected $folder_name = "backend.annualreport."; public function index() { $reportAnnuals = ReportAnnual::orderByDesc('created_at')->get(); return view($this->folder_name.'index', compact('reportAnnuals')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { return view($this->folder_name.'form'); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { DB::beginTransaction(); try { $input = $request->all(); $input['user_id']=auth()->user()->id; $input['slug']=Str::slug($request->title['en']. rand(00000, 99999)); $input['title']=$request->title; ReportAnnual::create($input); DB::commit(); return redirect()->route('reportAnnual.index')->with('success', 'File is saved successfully.'); } catch (\Throwable $th) { DB::rollBack(); return back()->withInput(); } } /** * Display the specified resource. * * @param \App\Models\ReportAnnual $reportAnnual * @return \Illuminate\Http\Response */ public function show(ReportAnnual $reportAnnual) { // } /** * Show the form for editing the specified resource. * * @param \App\Models\ReportAnnual $reportAnnual * @return \Illuminate\Http\Response */ public function edit(ReportAnnual $reportAnnual) { return view($this->folder_name.'form', compact('reportAnnual')); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\ReportAnnual $reportAnnual * @return \Illuminate\Http\Response */ public function update(Request $request, ReportAnnual $reportAnnual) { // return $request; DB::beginTransaction(); try { $input = $request->all(); // return $input; $input['slug']=Str::slug($request->title['en']. rand(00000, 99999)); $input['title']=$request->title; $reportAnnual->update($input); DB::commit(); return redirect()->route('reportAnnual.index')->with('success', 'File is updated successfully.'); } catch (\Throwable $th) { DB::rollBack(); return back()->withInput(); } } /** * Remove the specified resource from storage. * * @param \App\Models\ReportAnnual $reportAnnual * @return \Illuminate\Http\Response */ public function destroy(ReportAnnual $reportAnnual) { try { $reportAnnual->delete(); return back()->with('Success', 'Succesfully Deleted Your Data'); } catch (\Throwable $th) { return $th->getMessage(); return back(); } } }