Skip to content

Commit

Permalink
Formular de inregistrare utilizator nou + controller pentru salvarea …
Browse files Browse the repository at this point in the history
…in baza de date terminat. Camp pentru adaugarea pozei de profil inceput
  • Loading branch information
brobert04 committed Dec 16, 2022
1 parent 3d00709 commit d75bd19
Show file tree
Hide file tree
Showing 9 changed files with 64,623 additions and 3 deletions.
18 changes: 18 additions & 0 deletions app/Http/Controllers/Admin/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Requests\CreateUserRequest;
use App\Models\User;

class UsersController extends Controller
Expand All @@ -15,4 +16,21 @@ public function showUsers(){
$users = User::all()->sortBy('name');
return view('admin.users')->with('users', $users);
}
public function newUser(){
return view('admin.new-users');
}

public function createUser(CreateUserRequest $request){

$user = new User();
$user->name = $request->name;
$user->email = $request->email;
$user->phone = $request->phone_number;
$user->address = $request->address;
$user->role = $request->role;
$user->password =bcrypt($request->password);

$user->save();
return redirect(route('users'))->with('success', 'User created successfully');
}
}
50 changes: 50 additions & 0 deletions app/Http/Requests/CreateUserRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class CreateUserRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
'name'=>'required|max:50',
'email'=>'required|email|unique:users',
'phone_number'=>'max:100|',
'address'=>'max:100',
'role'=>'required',
'password'=>'required|min:8|confirmed',
];
}
public function messages(){
return [
'name.required'=>'Numele este obligatoriu',
'name.max'=>'Numele nu poate avea mai mult de 50 de caractere',
'email.required'=>'Email-ul este obligatoriu',
'email.email'=>'Email-ul nu este valid',
'email.unique'=>'Email-ul este deja folosit',
'phone_number.max'=>'Numărul de telefon nu poate avea mai mult de 100 de caractere',
'address.max'=>'Adresa nu poate avea mai mult de 100 de caractere',
'role.required'=>'Rolul este obligatoriu',
'password.required'=>'Parola este obligatorie',
'password.min'=>'Parola trebuie să aibă minim 8 caractere',
'password.confirmed'=>'Parolele nu se potrivesc',
];
}
}
Loading

0 comments on commit d75bd19

Please sign in to comment.