1. Go to this page and download the library: Download risan/laravel-auth-service library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use AuthService;
// Log the user in.
$credentials = ['email' => '[email protected]', 'password' => 'secret'];
AuthService::login($credentials);
// Log the user out.
AuthService::logout();
namespace App\Http\Controllers\Auth;
use AuthService;
use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\LoginRequest;
class AuthController extends Controller
{
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}
/**
* Show the login page.
*
* @return Illuminate\Http\Response
*/
public function getLogin()
{
return view('auth.login');
}
/**
* Handle login request.
*
* @param App\Http\Requests\Auth\LoginRequest $request
* @return Illuminate\Http\Response
*/
public function postLogin(LoginRequest $request)
{
$credentials = $request->only(['email', 'password']);
return AuthService::login($credentials, $request->has('remember'));
}
/**
* Log the user out.
*
* @return Illuminate\Http\Response
*/
public function getLogout()
{
return AuthService::logout();
}
}
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\LoginRequest;
use AuthService\Contracts\AuthServiceInterface;
class AuthController extends Controller
{
protected $authService;
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct(AuthServiceInterface $authService)
{
$this->middleware('guest', ['except' => 'getLogout']);
$this->authService = $authService;
}
/**
* Show the login page.
*
* @return Illuminate\Http\Response
*/
public function getLogin()
{
return view('auth.login');
}
/**
* Handle login request.
*
* @param App\Http\Requests\Auth\LoginRequest $request
* @return Illuminate\Http\Response
*/
public function postLogin(LoginRequest $request)
{
$credentials = $request->only(['email', 'password']);
return $this->authService->login($credentials, $request->has('remember'));
}
/**
* Log the user out.
*
* @return Illuminate\Http\Response
*/
public function getLogout()
{
return $this->authService->logout();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.