관리-도구
편집 파일: RecentUpdateController.php
<?php namespace App\Http\Controllers; use App\Models\Downloads; use Illuminate\Support\Str; use App\Models\RecentUpdate; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Http\Requests\RecentRequest; use App\Http\Requests\RecentUpdateRequest; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; class RecentUpdateController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ protected $folder_name = "backend.recentupdate."; protected $recentupdate=null; public function __construct(RecentUpdate $recentupdate) { $this->recentupdate=$recentupdate; } public function index() { $recentUpdates = RecentUpdate::all(); return view($this->folder_name.'index', compact('recentUpdates')); } /** * 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(RecentRequest $request) { DB::beginTransaction(); try { $data = $request->all(); $data['user_id']=auth()->user()->id; $data['slug']=Str::slug($request->title['en']. rand(00000, 99999)); $data['title']=$request->title; $this->recentupdate->fill($data); $this->recentupdate->save(); DB::commit(); return redirect()->route('recentUpdate.index')->with('success', 'File is saved successfully.'); } catch (\Throwable $th) { DB::rollBack(); return back()->withdata(); } } /** * Display the specified resource. * * @param \App\Models\RecentUpdate $recentUpdate * @return \Illuminate\Http\Response */ public function show(RecentUpdate $recentUpdate) { } /** * Show the form for editing the specified resource. * * @param \App\Models\RecentUpdate $recentUpdate * @return \Illuminate\Http\Response */ public function edit(RecentUpdate $recentUpdate) { return view($this->folder_name.'form', compact('recentUpdate')); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\RecentUpdate $recentUpdate * @return \Illuminate\Http\Response */ public function update(RecentUpdateRequest $request, RecentUpdate $recentUpdate) { // return $request->; DB::beginTransaction(); try { $input = $request->all(); $input['slug']=Str::slug($request->title['en']. rand(00000, 99999)); $input['title']=$request->title; $recentUpdate->update($input); DB::commit(); return redirect()->route('recentUpdate.index')->with('success', 'File is updated successfully.'); } catch (\Throwable $th) { DB::rollBack(); return back()->withInput(); } } /** * Remove the specified resource from storage. * * @param \App\Models\RecentUpdate $recentUpdate * @return \Illuminate\Http\Response */ public function destroy(RecentUpdate $recentUpdate) { try { $recentUpdate->delete(); return back()->with('Success', 'Succesfully Deleted Your Data'); } catch (\Throwable $th) { return $th->getMessage(); return back(); } } }