diff --git a/Modules/User/app/Http/Controllers/UserController.php b/Modules/User/app/Http/Controllers/UserController.php index 8d68047..b1a101a 100644 --- a/Modules/User/app/Http/Controllers/UserController.php +++ b/Modules/User/app/Http/Controllers/UserController.php @@ -6,12 +6,20 @@ 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(); @@ -25,6 +33,7 @@ class UserController extends Controller public function create() { $data['title'] = "Create User"; + $data['users'] = User::latest()->get(); return view('user::create', $data); } @@ -33,12 +42,21 @@ class UserController extends Controller */ 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'); diff --git a/Modules/User/app/Repositories/UserInterface.php b/Modules/User/app/Repositories/UserInterface.php new file mode 100644 index 0000000..dc8f48b --- /dev/null +++ b/Modules/User/app/Repositories/UserInterface.php @@ -0,0 +1,12 @@ +roles()->attach($role); + } + + public function update($userId, array $newDetails) + { + return User::whereId($userId)->update($newDetails); + } + +} diff --git a/Modules/User/database/migrations/2024_04_07_095204_add_employee_id_to_users_table.php b/Modules/User/database/migrations/2024_04_07_095204_add_employee_id_to_users_table.php new file mode 100644 index 0000000..f28ac96 --- /dev/null +++ b/Modules/User/database/migrations/2024_04_07_095204_add_employee_id_to_users_table.php @@ -0,0 +1,28 @@ +unsignedInteger('employee_id'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + + }); + } +}; diff --git a/Modules/User/resources/views/create.blade.php b/Modules/User/resources/views/create.blade.php index 166da0d..ca29ca4 100644 --- a/Modules/User/resources/views/create.blade.php +++ b/Modules/User/resources/views/create.blade.php @@ -15,13 +15,12 @@