<?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);
});
}
}
composer require laravel/ui
php artisan ui vue --auth
npm install && npm run dev
public function __construct()
{
$this->middleware(function ($request, $next) {
$this->user = Auth::user();
return $next($request);
});
}
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
<?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');
}
}
Auth::user();
// Only for laravel 6.x and higher
composer require laravel/ui "^1.0" --dev
php artisan ui vue --auth
//namespace
use IlluminateSupportFacadesAuth;
// Laravel 5.x
php artisan make:auth
composer require laravel/ui:^2.4
php artisan ui vue --auth
composer require laravel/ui "^2.0"