ok
Direktori : /home2/selectio/public_html/3idiotsgadgetstore.in/app/Http/Controllers/Admin/ |
Current File : /home2/selectio/public_html/3idiotsgadgetstore.in/app/Http/Controllers/Admin/EmployeeController.php |
<?php namespace App\Http\Controllers\Admin; use App\CPU\Helpers; use App\CPU\ImageManager; use App\Http\Controllers\Controller; use App\Model\Admin; use App\Model\AdminRole; use Brian2694\Toastr\Facades\Toastr; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class EmployeeController extends Controller { public function add_new() { $rls = AdminRole::whereNotIn('id', [1])->get(); return view('admin-views.employee.add-new', compact('rls')); } public function store(Request $request) { $request->validate([ 'name' => 'required', 'role_id' => 'required', 'image' => 'required', 'email' => 'required|email|unique:admins', 'password'=>'required', 'phone'=>'required' ], [ 'name.required' => 'Role name is required!', 'role_name.required' => 'Role id is Required', 'email.required' => 'Email id is Required', 'image.required' => 'Image is Required', ]); if ($request->role_id == 1) { Toastr::warning('Access Denied!'); return back(); } DB::table('admins')->insert([ 'name' => $request->name, 'phone' => $request->phone, 'email' => $request->email, 'admin_role_id' => $request->role_id, 'password' => bcrypt($request->password), 'status'=>1, 'image' => ImageManager::upload('admin/', 'png', $request->file('image')), 'created_at' => now(), 'updated_at' => now(), ]); Toastr::success('Employee added successfully!'); return redirect()->route('admin.employee.list'); } function list(Request $request) { $search = $request['search']; $key = explode(' ', $request['search']); $em = Admin::with(['role'])->whereNotIn('id', [1]) ->when($search!=null, function($query) use($key){ foreach ($key as $value) { $query->where('name', 'like', "%{$value}%") ->orWhere('phone', 'like', "%{$value}%") ->orWhere('email', 'like', "%{$value}%"); } }) ->paginate(Helpers::pagination_limit()); return view('admin-views.employee.list', compact('em','search')); } public function edit($id) { $e = Admin::where(['id' => $id])->first(); $rls = AdminRole::whereNotIn('id', [1])->get(); return view('admin-views.employee.edit', compact('rls', 'e')); } public function update(Request $request, $id) { $request->validate([ 'name' => 'required', 'role_id' => 'required', 'email' => 'required|email|unique:admins,email,'.$id, ], [ 'name.required' => 'Role name is required!', ]); if ($request->role_id == 1) { Toastr::warning('Access Denied!'); return back(); } $e = Admin::find($id); if ($request['password'] == null) { $pass = $e['password']; } else { if (strlen($request['password']) < 7) { Toastr::warning('Password length must be 8 character.'); return back(); } $pass = bcrypt($request['password']); } if ($request->has('image')) { $e['image'] = ImageManager::update('admin/', $e['image'], 'png', $request->file('image')); } DB::table('admins')->where(['id' => $id])->update([ 'name' => $request->name, 'phone' => $request->phone, 'email' => $request->email, 'admin_role_id' => $request->role_id, 'password' => $pass, 'image' => $e['image'], 'updated_at' => now(), ]); Toastr::success('Employee updated successfully!'); return back(); } public function status(Request $request) { $employee = Admin::find($request->id); $employee->status = $request->status; $employee->save(); Toastr::success('Employee status updated!'); return back(); } }