Эко система


Download 1.63 Mb.
bet13/15
Sana19.06.2023
Hajmi1.63 Mb.
#1603310
1   ...   7   8   9   10   11   12   13   14   15
Bog'liq
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:
1   ...   7   8   9   10   11   12   13   14   15




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling