email)->first() == null){ $user = new User; $user->name = $request->name; $user->email = $request->email; $user->phone = $request->mobile; $user->user_type = "staff"; $user->password = Hash::make($request->password); if($user->save()){ $staff = new Staff; $staff->user_id = $user->id; $staff->role_id = $request->role_id; if($staff->save()){ flash(translate('Staff has been inserted successfully'))->success(); return redirect()->route('staffs.index'); } } } flash(translate('Email already used'))->error(); return back(); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $staff = Staff::findOrFail(decrypt($id)); $roles = Role::all(); return view('backend.staff.staffs.edit', compact('staff', 'roles')); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $staff = Staff::findOrFail($id); $user = $staff->user; $user->name = $request->name; $user->email = $request->email; $user->phone = $request->mobile; if(strlen($request->password) > 0){ $user->password = Hash::make($request->password); } if($user->save()){ $staff->role_id = $request->role_id; if($staff->save()){ flash(translate('Staff has been updated successfully'))->success(); return redirect()->route('staffs.index'); } } flash(translate('Something went wrong'))->error(); return back(); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { User::destroy(Staff::findOrFail($id)->user->id); if(Staff::destroy($id)){ flash(translate('Staff has been deleted successfully'))->success(); return redirect()->route('staffs.index'); } flash(translate('Something went wrong'))->error(); return back(); } }