fadlyshafa

Untitled

Feb 22nd, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.24 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers\Dashboard;
  4.  
  5. use Illuminate\Http\Request;
  6. use App\Http\Controllers\Controller;
  7.  
  8. use App\User;
  9. use App\Models\Biodata;
  10.  
  11. class Peserta_controller extends Controller
  12. {
  13.     public function index(){
  14.         $title = 'Data peserta';
  15.         $data = User::withCount('biodata_r')->whereNull('role')->orderBy('name','asc')->get();
  16.  
  17.         return view('dashboard.peserta.index',compact('title','data'));
  18.     }
  19.  
  20.     public function diverifikasi(){
  21.         $title = 'Data peserta yang sudah di verifikasi';
  22.         $data = User::withCount('biodata_r')->where('is_verifikasi',1)->orderBy('name','asc')->get();
  23.  
  24.         return view('dashboard.peserta.index',compact('title','data'));
  25.     }
  26.  
  27.     public function belum_verifikasi(){
  28.         $title = 'Data peserta yang belum di verifikasi';
  29.         $data = User::withCount('biodata_r')->whereNull('is_verifikasi')->orderBy('name','asc')->get();
  30.  
  31.         return view('dashboard.peserta.index',compact('title','data'));
  32.     }
  33.  
  34.     public function edit($id){
  35.         $title = 'Edit Data peserta';
  36.         $dt = User::with('biodata_r')->find($id);
  37.  
  38.         return view('dashboard.peserta.edit',compact('title','dt'));
  39.     }
  40.  
  41.     public function update(Request $request,$id){
  42.         try {
  43.             // update data kedalam table users
  44.             $user['email'] = $request->email;
  45.             $user['name'] = $request->name;
  46.             $user['nisn'] = $request->nisn;
  47.             $user['updated_at'] = date('Y-m-d H:i:s');
  48.  
  49.             $file = $request->file('photo');
  50.             if($file){
  51.                 $nama_file = $file->getClientOriginalName();
  52.                 $file->move('uploads',$nama_file);
  53.                 $user['photo'] = 'uploads/'.$nama_file;
  54.             }
  55.  
  56.             User::where('id',$id)->update($user);
  57.  
  58.             // update data kedalam table biodata
  59.             $biodata['no_hp'] = $request->no_hp;
  60.             $biodata['alamat'] = $request->alamat;
  61.             $biodata['tempat_lahir'] = $request->tempat_lahir;
  62.             $biodata['tanggal_lahir'] = $request->tanggal_lahir;
  63.             $biodata['updated_at'] = date('Y-m-d H:i:s');
  64.  
  65.             $ijazah = $request->file('ijazah');
  66.             if($ijazah){
  67.                 $nama_file = $ijazah->getClientOriginalName();
  68.                 $ijazah->move('biodata_files',$nama_file);
  69.                 $biodata['ijazah'] = 'biodata_files/'.$nama_file;
  70.             }
  71.  
  72.             $ktp = $request->file('ktp');
  73.             if($ktp){
  74.                 $nama_file = $ktp->getClientOriginalName();
  75.                 $ktp->move('biodata_files',$nama_file);
  76.                 $biodata['ktp'] = 'biodata_files/'.$nama_file;
  77.             }
  78.  
  79.             Biodata::where('users',$id)->update($biodata);
  80.  
  81.             \Session::flash('sukses','Data peserta berhasil di update');
  82.  
  83.         } catch (\Exception $e) {
  84.             \Session::flash('gagal',$e->getMessage());
  85.         }
  86.  
  87.         return redirect()->back();
  88.     }
  89.  
  90.     public function delete($id){
  91.         try {
  92.             User::where('id',$id)->delete();
  93.  
  94.             \Session::flash('sukses','Data berhasil dihapus');
  95.         } catch (\Exception $e) {
  96.             \Session::flash('gagal',$e->getMessage());
  97.         }
  98.         return redirect()->back();
  99.     }
  100. }
Add Comment
Please, Sign In to add comment