Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel get auth user in constructor

<?php

namespace AppHttpControllers;

use AppUser;
use IlluminateSupportFacadesAuth;
use AppHttpControllersController;

class ProjectController extends Controller
{
    /**
     * All of the current user's projects.
     */
    protected $projects;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware(function ($request, $next) {
            $this->projects = Auth::user()->projects;

            return $next($request);
        });
    }
}
Comment

laravel auth

composer require laravel/ui

php artisan ui vue --auth

npm install && npm run dev
Comment

laravel auth user in constructor

public function __construct()
{
  $this->middleware(function ($request, $next) {
    $this->user = Auth::user();
    return $next($request);
  });
}
Comment

laravel make auth

Laravel's laravel/ui package provides a quick way to scaffold all of the routes and views you need for authentication using a few simple commands:

composer require laravel/ui

php artisan ui vue --auth
Comment

custom laravel auth

<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use Hash;
use Session;
use AppModelsUser;
use IlluminateSupportFacadesAuth;
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');
    }
}
Comment

get user auth in laravel

Auth::user();
Comment

laravel setup auth

// Only for laravel 6.x and higher
composer require laravel/ui "^1.0" --dev

php artisan ui vue --auth
Comment

laravel auth

//namespace
use IlluminateSupportFacadesAuth;
Comment

laravel setup auth

// Laravel 5.x
php artisan make:auth
Comment

laravel make auth

composer require laravel/ui:^2.4
 
php artisan ui vue --auth
Comment

make auth in laravel 7

composer require laravel/ui "^2.0"
Comment

PREVIOUS NEXT
Code Example
Php :: laravel 8: bootstrap 
Php :: laravel delete controller still cached 
Php :: what is scalar data type in php 
Php :: supervisor configuration for laravel queue 
Php :: convert timestamp to date php 
Php :: php.ini location 
Php :: paginate relationship laravel7 
Php :: php auto redirect 
Php :: php array check value exists 
Php :: woocommerce show data to cart page 
Php :: replace 0 in number to add 234 php 
Php :: laravel empty query result 
Php :: laravel log build custom channel 
Php :: laravel middleware route 
Php :: php check for null 
Php :: php hash 
Php :: search by date using carbon laravel 
Php :: convert any phone number in us number format php 
Php :: delete multiple row by model in laravel 
Php :: date to string php 
Php :: php do while loop 
Php :: infinite cookie good php ? 
Php :: php date function get previous month 
Php :: laravel apache public folder 
Php :: laravel run specific feature test 
Php :: str_ireplace 
Php :: array_push 
Php :: laravel how to check if there are record exists 
Php :: how convert the date and time to integer in laravel 
Php :: php time 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =