PHP code example of nylo / laravel-nylo-auth

1. Go to this page and download the library: Download nylo/laravel-nylo-auth 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/ */

    

nylo / laravel-nylo-auth example snippets


use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens, Notifiable;
    // ...
}

// config/laravel-nylo-auth.php

return [
    // The Eloquent model used for authentication
    'user_model' => \App\Models\User::class,

    // Rate limiter classes for each route group
    'rate_limits' => [
        'public' => \Nylo\LaravelNyloAuth\RateLimiters\PublicRateLimiter::class,         // 5 req/min by IP
        'authenticated' => \Nylo\LaravelNyloAuth\RateLimiters\AuthenticatedRateLimiter::class, // 60 req/min by user
    ],
];

use Nylo\LaravelNyloAuth\Contracts\RateLimiterContract;
use Illuminate\Cache\RateLimiting\Limit;

class MyPublicRateLimiter implements RateLimiterContract
{
    public function configure(): Limit|array
    {
        return Limit::perMinute(10)->by(request()->ip())->response(function () {
            return response()->json(['message' => 'Too many requests'], 429);
        });
    }
}

'rate_limits' => [
    'public' => \App\RateLimiters\MyPublicRateLimiter::class,
    'authenticated' => \Nylo\LaravelNyloAuth\RateLimiters\AuthenticatedRateLimiter::class,
],

'middleware' => [
    'public' => ['locale'],              // login, register, forgot-password
    'authenticated' => ['log.requests'], // authenticated endpoints (e.g. /user)

    // Target individual routes by their full name
    'routes' => [
        'nylo.api.v1.register' => ['captcha'],
        'nylo.api.v1.auth.user' => ['log.user.access'],
    ],
],
bash
php artisan vendor:publish --provider="Nylo\LaravelNyloAuth\LaravelNyloAuthServiceProvider"