Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function index(){
- $title = 'header slider';
- return view('header_slider.index',compact('title'));
- }
- public function add(){
- $title = 'add header slider';
- return view('header_slider.add',compact('title'));
- }
- public function store(Request $request){
- try {
- $a = $request->except(['_token','_method','photo']);
- $a['id'] = \Uuid::generate(4);
- $a['created_at'] = date('Y-m-d H:i:s');
- $a['updated_at'] = date('Y-m-d H:i:s');
- $file = $request->file('photo');
- if($file){
- $file->move('header_slider',$file->getClientOriginalName());
- $a['photo'] = $file->getClientOriginalName();
- }else{
- $a['photo'] = null;
- }
- M_header::insert($a);
- \Session::flash('sukses','data berhasil ditambah');
- return redirect('header-slider');
- } catch (\Exception $e) {
- \Session::flash('gagal',$e->getMessage());
- return redirect('header-slider/add');
- }
- }
- public function edit($id){
- $title = 'edit header slider';
- $dt = M_header::where('id',$id)->first();
- return view('header_slider.edit',compact('title','dt'));
- }
- public function update(Request $request,$id){
- try {
- $a = $request->except(['_token','_method','photo']);
- // $a['id'] = \Uuid::generate(4);
- // $a['created_at'] = date('Y-m-d H:i:s');
- $a['updated_at'] = date('Y-m-d H:i:s');
- $file = $request->file('photo');
- if($file){
- $file->move('header_slider',$file->getClientOriginalName());
- $a['photo'] = $file->getClientOriginalName();
- }else{
- $a['photo'] = null;
- }
- M_header::where('id',$id)->update($a);
- \Session::flash('sukses','data berhasil diupdate');
- return redirect('header-slider');
- } catch (\Exception $e) {
- \Session::flash('gagal',$e->getMessage());
- return redirect('header-slider/'.$id);
- }
- }
- public function delete($id){
- try {
- M_header::where('id',$id)->delete();
- \Session::flash('sukses','data berhasil dihapus');
- } catch (\Exception $e) {
- \Session::flash('gagal',$e->getMessage());
- }
- return redirect('header-slider');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement