Advertisement
fadlyshafa

Untitled

Dec 3rd, 2019
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.24 KB | None | 0 0
  1. public function index(){
  2.         $title = 'header slider';
  3.  
  4.         return view('header_slider.index',compact('title'));
  5.     }
  6.  
  7.     public function add(){
  8.         $title = 'add header slider';
  9.  
  10.         return view('header_slider.add',compact('title'));
  11.     }
  12.  
  13.     public function store(Request $request){
  14.         try {
  15.             $a = $request->except(['_token','_method','photo']);
  16.             $a['id'] = \Uuid::generate(4);
  17.             $a['created_at'] = date('Y-m-d H:i:s');
  18.             $a['updated_at'] = date('Y-m-d H:i:s');
  19.  
  20.             $file = $request->file('photo');
  21.             if($file){
  22.                 $file->move('header_slider',$file->getClientOriginalName());
  23.                 $a['photo'] = $file->getClientOriginalName();
  24.             }else{
  25.                 $a['photo'] = null;
  26.             }
  27.  
  28.             M_header::insert($a);
  29.  
  30.             \Session::flash('sukses','data berhasil ditambah');
  31.  
  32.             return redirect('header-slider');
  33.         } catch (\Exception $e) {
  34.             \Session::flash('gagal',$e->getMessage());
  35.  
  36.             return redirect('header-slider/add');
  37.         }
  38.     }
  39.  
  40.     public function edit($id){
  41.         $title = 'edit header slider';
  42.         $dt = M_header::where('id',$id)->first();
  43.  
  44.         return view('header_slider.edit',compact('title','dt'));
  45.     }
  46.  
  47.     public function update(Request $request,$id){
  48.         try {
  49.             $a = $request->except(['_token','_method','photo']);
  50.             // $a['id'] = \Uuid::generate(4);
  51.             // $a['created_at'] = date('Y-m-d H:i:s');
  52.             $a['updated_at'] = date('Y-m-d H:i:s');
  53.  
  54.             $file = $request->file('photo');
  55.             if($file){
  56.                 $file->move('header_slider',$file->getClientOriginalName());
  57.                 $a['photo'] = $file->getClientOriginalName();
  58.             }else{
  59.                 $a['photo'] = null;
  60.             }
  61.  
  62.             M_header::where('id',$id)->update($a);
  63.  
  64.             \Session::flash('sukses','data berhasil diupdate');
  65.  
  66.             return redirect('header-slider');
  67.         } catch (\Exception $e) {
  68.             \Session::flash('gagal',$e->getMessage());
  69.  
  70.             return redirect('header-slider/'.$id);
  71.         }
  72.     }
  73.  
  74.     public function delete($id){
  75.         try {
  76.             M_header::where('id',$id)->delete();
  77.  
  78.             \Session::flash('sukses','data berhasil dihapus');
  79.         } catch (\Exception $e) {
  80.             \Session::flash('gagal',$e->getMessage());
  81.         }
  82.         return redirect('header-slider');
  83.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement