Answers for "laravel 9 custom authentication with username"

PHP
17

create laravel 9 auth

laravel new projectNew
composer require laravel/ui
php artisan ui bootstrap --auth
npm install
npm run dev
Posted by: Guest on March-11-2022
2

laravel authentication in laravel 8

1. if(is_global_laravel_installer_installed){
    		larvel new laravel_project_name
	}else{
            composer create-project laravel/laravel laravel_project_name
    }
2. composer require laravel/ui  
3. php artisan ui vue --auth  
   or
   php artisan ui bootstrap --auth
4. npm install 
5. npm run dev
Now your Laravel auth system is ready to use with latest version.
  #laravel installation
Posted by: Guest on December-15-2021
0

custom laravel auth

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Hash;
use Session;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
class CustomAuthController extends Controller
{
    public function index()
    {
        return view('auth.login');
    }  
      
    public function customLogin(Request $request)
    {
        $request->validate([
            'email' => 'required',
            'password' => 'required',
        ]);
   
        $credentials = $request->only('email', 'password');
        if (Auth::attempt($credentials)) {
            return redirect()->intended('dashboard')
                        ->withSuccess('Signed in');
        }
  
        return redirect("login")->withSuccess('Login details are not valid');
    }

    public function registration()
    {
        return view('auth.registration');
    }
      
    public function customRegistration(Request $request)
    {  
        $request->validate([
            'name' => 'required',
            'email' => 'required|email|unique:users',
            'password' => 'required|min:6',
        ]);
           
        $data = $request->all();
        $check = $this->create($data);
         
        return redirect("dashboard")->withSuccess('You have signed-in');
    }

    public function create(array $data)
    {
      return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => Hash::make($data['password'])
      ]);
    }    
    
    public function dashboard()
    {
        if(Auth::check()){
            return view('dashboard');
        }
  
        return redirect("login")->withSuccess('You are not allowed to access');
    }
    
    public function signOut() {
        Session::flush();
        Auth::logout();
  
        return Redirect('login');
    }
}
Posted by: Guest on February-21-2022

Code answers related to "laravel 9 custom authentication with username"

Browse Popular Code Answers by Language