New-OMIS/Modules/User/app/Http/Controllers/UserController.php

91 lines
2.0 KiB
PHP
Raw Permalink Normal View History

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