Download the PHP package risan/laravel-auth-service without Composer
On this page you can find all versions of the php package risan/laravel-auth-service. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download risan/laravel-auth-service
More information about risan/laravel-auth-service
Files in risan/laravel-auth-service
Package laravel-auth-service
Short Description Laravel stateful authentication service provider.
License MIT
Homepage https://github.com/risan/laravel-auth-service
Informations about the package laravel-auth-service
Laravel Authentication Service
Stateful authentication service provider for the latest Laravel 5.2 version.
Laravel already offers a handy way to provide user authentication functionality. Laravel framework ships with AuthenticatesUsers
trait which can be injected to your authentication controller. And actually, by default the provided AuthController
class are using this handy trait.
This package's intention is to replace the AuthenticatesUsers
trait from your authentication controller. By extracting the authentication logic into a seperate service provider, your authentication controller will be a lot more clean and readable.
This package is only for the latest Laravel 5.2 version and only supports the StatefulGuard
implementation.
Table of Contents
- Dependencies
- Installation
- Package Installation
- Service Provider Registration
- Facade Registration
- Publish Configuration File
- Configuration
- Available Methods
- Login
- Logout
- Basic Usage
- Implementation in AuthController
- Using Facade
- Without Facade
Dependencies
This package relies on the following libraries:
Installation
Package Installation
To install this library using Composer, simply run the following command inside your Laravel project directory:
Or you may also add risan/laravel-auth-service
package into your composer.json
file:
Once the dependency is added, run the install command:
Service Provider Registration
Once the package has been installed, you need to register package's service provider. Open your config/app.php
file, and add AuthService\AuthServiceProvider::class
into your providers
list like so:
Facade Registration
If you would like to use facade to access this package, you need to register the AuthService\Facades\AuthService::class
in aliases
directive. Open up your config/app.php
file, and update the aliases
directive like so:
This way, you may access the package functionality using AuthService
facade.
Publish Configuration File
The last step to setup this package is to publish the configuration file. On your command prompt, run the following artisan command:
This command will copy a default package's configuration file in config/authservice.php
.
Configuration
Once the package's configuration file is published, you may locate the file in config\authservice.php
. The default configuration file will look like this:
-
auth_event_listener_class
This configuration tells the service provider which authentication event listener class to use. By default it will use the provided
AuthService\AuthEventListener
class. However you may also override it with your own event listener implementation as long as it confronts theAuthService\Contracts\AuthEventListenerInterface
contract. -
login_failed_message
This is the error message that will be used when user's credentials is invalid. By default this error message will be flashed out to the session if login is failed.
-
after_login_success_path
This is the path where user will be redirected to if he/she successfully logged in.
-
after_logout_success_path
This is the path where user will be redirected to if he/she logged out from application.
Available Methods
Login
To log the user in, simply call the login()
method:
This method will attempt to log the user in and will return an instance of Illuminate\Http\RedirectResponse
.
Logout
To log the user out, we may use the logout()
method:
This method will also return an instance of Illuminate\Http\RedirectResponse
.
Basic Usage
Here is some basic example to perform login and logout functionality, assuming that we are using the facade.
Implementation in AuthController
For a complete implementation, we will create a simple authentication controller that handles the login and logout request.