mark-villudo/laravel-login is a Laravel package for laravel package api and in cms login..
It currently has 1 GitHub stars and 10 downloads on Packagist.
Install it with composer require mark-villudo/laravel-login.
Discover more Laravel packages by mark-villudo
or browse all Laravel packages to compare alternatives.
Last updated
Laravel package API and in CMS login.
Require this package with composer.
//Passport requires league/oauth2-server which requires defuse/php-encryption hence the issues.
//See https://github.com/paragonie/random_compat/issues/147
composer require paragonie/random_compat:2.*
composer require mark-villudo/laravel-login
##Setup Laravel Passport Configs.
'providers' => [
....
Laravel\Passport\PassportServiceProvider::class,
],
php artisan migrate
Next, we need to install passport using command, Using passport:install command, it will create token keys for security. So let's run bellow command:
php artisan passport:install
In model we added HasApiTokens class of Passport,
In AuthServiceProvider we added "Passport::routes()",
In auth.php, we added api auth configuration.
app/User.php
<?php
namespace App;
use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasApiTokens, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
app/Providers/AuthServiceProvider.php
<?php
namespace App\Providers;
use Laravel\Passport\Passport;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
'App\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
Passport::routes();
}
}
config/auth.php
return [
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
],
routes/api.php
<?php
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::post('login', 'Api\UserController@login');
Route::post('register', 'Api\UserController@register');
Route::group(['middleware' => 'auth:api'], function(){
Route::post('details', 'Api\UserController@details');
});
$table->boolean('status')->default(1);
php artisan make:resource UserResource
MarkVilludo\LaravelLogin\ServiceProvider::class,
php artisan vendor:publish --provider="MarkVilludo\LaravelLogin\ServiceProvider" --tag="config"
use MarkVilludo\LaravelLogin\Login;
public function __construct(Login $login)
{
$this->login = $login;
}
public function login(Request $request)
{
//Get email and password
$email = $request->email;
$password = $request->password;
$projectName = 'My Sample Project'; //used to include in generated token using passport API.
//use helper login user
return $this->login->loginApi($projectName, $email, $password);
}
php artisan vendor:publish --provider="MarkVilludo\LaravelLogin\ServiceProvider" --tag="views"
Route::get('/login', function () {
return view('login');
});
Route::post('/login', 'Auth\LoginController@login')->name('web.login');
//Run in terminal php artisan make:controller Admin/DashboardController --resource (this is for test only)
//You may create route based to your needs.
Route::resource('/dashboard','Admin\DashboardController');
public function login(Request $request)
{
//Get email and password and passed to function
$routeName = 'dashboard.index'; //used for redirect route.
//dashboard.index - its auto generated route when you add Route::resource('dashboard') in routes.
//But depends on you, Just need to pass the route name parameter.
//use helper login user
return $this->login->loginCMS($routeName, $request->email, $request->password);
}
The MIT License (MIT). Please see License File for more information.