@guest
// Show content if unauthenticated
@endguest
@auth
// The data only available for auth user
@endauth
{{ auth()->user()->email }}
// With Boothstrap
composer require laravel/ui --dev
php artisan ui bootstrap --auth
npm install
npm run build
npm run dev
composer require laravel/ui
php artisan ui vue --auth
npm install && npm run dev
<?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');
}
}
//Typical way:
@if(auth()->user())
// The user is authenticated.
@endif
//Shorter:
@auth
// The user is authenticated.
@endauth
//namespace
use IlluminateSupportFacadesAuth;