New-OMIS/Modules/User/app/Http/Controllers/UserController.php
2024-04-07 17:59:05 +05:45

91 lines
2.0 KiB
PHP

<?php
namespace Modules\User\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\User\Repositories\UserRepository;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*/
protected $userRepository;
public function __construct(UserRepository $userRepository){
$this->userRepository = $userRepository;
}
public function index()
{
$data = User::latest()->get();
$editable = false;
return view('user::index', compact('data', 'editable'));
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = "Create User";
$data['users'] = User::latest()->get();
return view('user::create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$validatedData = $request->validate([
'name' => 'required|min:5',
'email' => 'required',
'password' => 'required',
]);
$user = $this->userRepository->create($validatedData, $request->role);
toastr()->success('User has been created!');
return redirect()->route('users.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('user::show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = "Edit User";
$data['user'] = User::findOrFail($id);
return view('user::edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
//
}
}