Эко система
Download 1.63 Mb.
|
kirish
Controller fayllar:
UserController.php namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Http\Requests\UserStoreCoordinatorRequest; use App\Http\Requests\UserStoreRequest; use App\Http\Requests\UserUpdateRequest; use App\Models\Admin\Filial; use App\Models\Admin\Region; use App\Models\Admin\Role; use App\Models\Admin\Well; use Illuminate\Http\Request; use App\Models\User; use Illuminate\Support\Facades\Hash; class UserController extends Controller { public function index() { $users = User::sortable()->with('role')->fio(request()->query('full_name')) ->orderBy('created_at', 'DESC')->paginate(5); $roles = Role::where('key', '!=', 'super_admin')->get(); return view('admin.users.index', compact('users', 'roles')); } public function create() { return view('admin.users.create'); } public function store(UserStoreRequest $request) { $user = User::create($request->except('avatar')); if($request->has('avatar')){ $user->avatar = $user->uploadImage($request->avatar, 'users'); } return response()->json([ 'status' => 200 ]); } public function show(User $user) { return view('admin.users.show', compact('user')); } public function edit(User $user) { $avatar = asset($user->avatar); return response()->json([ 'status' => 200, 'user' => $user, 'avatar' => $avatar ]); } public function update(UserUpdateRequest $request, User $user) { if($request->has('avatar')){ $user->avatar = $user->uploadImage($request->avatar, 'users', $user->avatar); } if($request->password && $request->password == $request->password_confirm){ $user->password = Hash::make($request->password); } $user->update($request->except(['avatar', 'password', 'password_confirm', 'user_id'])); return response()->json([ 'status' => 200 ]); } public function destroy(User $user) { if(file_exists($user->avatar)){ unlink($user->avatar); } $user->delete(); return redirect()->route('admin.users.index'); }} Download 1.63 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling