middleware(function ($request, $next) { return $next($request); }); } public function index() { $menu_master = ''; $mandors = Mandor::all(); return view('staff.list-mandor',compact('mandors', 'menu_master')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $request->validate([ 'name' => 'required|max:50', 'email' => 'required|max:50', 'address_phone' => 'required', 'bank_info' => 'required', 'pekerjaan' => 'required' ]); $mandor = Mandor::create($request->except('act', 'id')); return redirect()->route('mandor.index')->with('msg', 'data berhasil ditambahkan'); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { if (\Request::ajax()) { $mandor = Mandor::findOrFail($id); return response()->json([ 'mandor' => $mandor, ]); } else { abort('404'); } } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { // } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $request->validate([ 'username' => 'required|max:255|unique:users,username,'.$request->id_user.',id', 'name' => 'required|max:50', 'address_phone' => 'required', 'nomor_keluarga' => 'required', 'email' => 'required|email|max:50|unique:mandors,email,'.$id.',id', 'alamat' => 'required', 'bank_info' => 'required', 'npwp' => 'required', 'area_pekerjaan' => 'required', 'ktp_mandor' => 'required', 'jenis_pekerjaan' => 'required', ]); $mandor = Mandor::where('id',$id)->update($request->except('act', 'id','_token','_method','id_user','from','username','ktp_mandor')); $mandor = Mandor::findOrFail($id); $location = public_path('uploads/'); $file = $request->file('ktp_mandor'); $file->move($location,$file->getClientOriginalName()); $mandor->ktp_mandor = 'uploads/'.$file->getClientOriginalName(); $mandor->save(); $mandor->user->username = $request->username; $mandor->user->alamat = $request->alamat; $mandor->user->email = $request->email; $mandor->user->fullname = $request->name; $mandor->user->no_telepon = $request->address_phone; $mandor->user->save(); if($request->from == 'mandor-home'){ return redirect()->route('mandor.home')->with('msg', 'data berhasil disimpan'); }else{ return redirect()->route('mandor.index')->with('msg', 'data berhasil dirubah'); } } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { Mandor::destroy($id); return redirect()->route('mandor.index')->with('msg', 'data berhasil dihapus'); } public function mandor(Request $request,$act = null) { if ($request->act == 'delete_pekerja') { DatabasePekerja::destroy($request->id); return redirect()->route('mandor.home')->with('msg','data berhasil dihapus'); }else{ $mandor = Auth::user()->mandor; $kosong = false; foreach ($mandor->toArray() as $key => $value) { if ($value == null) { $kosong = true; break; } } $menu_master = ''; return view('guest.mandor-home',compact('mandor','kosong','act', 'menu_master')); } } public function insert_pekerja(Request $request) { $ktp = $request->ktp?$request->ktp->openFile()->fread($request->ktp->getSize()):null; $dbp = DatabasePekerja::create([ 'nama' => $request->nama, 'no_hp' => $request->no_hp, 'no_hp_keluarga' => $request->no_hp_keluarga, 'keahlian' => $request->keahlian, 'ktp' => $ktp ]); if ($request->id_mandor) { $dbp->id_mandor = $request->id_mandor; $dbp->save(); } return redirect()->route('mandor.home')->with('msg','data berhasil ditambahkan'); } public function update_pekerja(Request $request,$id) { $ktp = $request->ktp?$request->ktp->openFile()->fread($request->ktp->getSize()):null; $dbp = DatabasePekerja::where('id',$id)->update([ 'nama' => $request->nama, 'no_hp' => $request->no_hp, 'no_hp_keluarga' => $request->no_hp_keluarga, 'keahlian' => $request->keahlian, ]); if($ktp){ $dbp = DatabasePekerja::where('id',$id)->update(['ktp' => $ktp]); } return redirect()->route('mandor.home')->with('msg','data berhasil diperbarui'); } }