forked from aslan/applicant-site
refactoring User resource
This commit is contained in:
parent
2a21e25200
commit
fc706fce82
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers\admin;
|
||||||
|
|
||||||
use App\Http\Requests\UpdateUserRequest;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\admin\UpdateUserRequest;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Auth\Events\PasswordReset;
|
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
use Illuminate\Contracts\View\View;
|
use Illuminate\Contracts\View\View;
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\Application;
|
||||||
|
@ -15,16 +15,12 @@ use Illuminate\Support\Str;
|
||||||
|
|
||||||
class UserController extends Controller
|
class UserController extends Controller
|
||||||
{
|
{
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->middleware('auth');
|
|
||||||
}
|
|
||||||
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||||
{
|
{
|
||||||
abort_if(Auth::user()->name !== 'admin', 403);
|
abort_if(Auth::user()->name !== 'admin', 403);
|
||||||
|
|
||||||
$users = User::all();
|
$users = User::all();
|
||||||
return view('users.index', compact('users'));
|
return view('admin.users.index', compact('users'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(UpdateUserRequest $request): RedirectResponse
|
public function store(UpdateUserRequest $request): RedirectResponse
|
||||||
|
@ -46,14 +42,14 @@ class UserController extends Controller
|
||||||
{
|
{
|
||||||
abort_if(Auth::user()->name !== 'admin', 403);
|
abort_if(Auth::user()->name !== 'admin', 403);
|
||||||
|
|
||||||
return view('users.create');
|
return view('admin.users.create');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit(User $user): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
public function edit(User $user): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||||
{
|
{
|
||||||
abort_if(Auth::user()->name !== 'admin', 403);
|
abort_if(Auth::user()->name !== 'admin', 403);
|
||||||
|
|
||||||
return view('users.edit', compact('user'));
|
return view('admin.users.edit', compact('user'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(UpdateUserRequest $request, User $user): RedirectResponse
|
public function update(UpdateUserRequest $request, User $user): RedirectResponse
|
Loading…
Reference in New Issue