PHP code example of makkinga / laravel-trusted-devices

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

    

makkinga / laravel-trusted-devices example snippets


return [
    # Overwrite the auto detection of the guard
    'guard'      => null,
    
    # The layout to use for the views
    'layout'     => 'layouts.app',
    
    # The middleware to use for the routes
    'middleware' => ['web', 'auth'],
    
    # Automatically trust the first device
    'trust_first_device' => true
];

use Illuminate\Notifications\Notifiable;
use Makkinga\TrustedDevices\Traits\HasTrustedDevices;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable, HasTrustedDevices;
}

use Makkinga\TrustedDevices\Middleware\EnsureDeviceIsTrusted;

protected $routeMiddleware = [
    [...]
    'trusted' => EnsureDeviceIsTrusted::class,
];

Route::middleware(['auth', 'trusted'])->group(function () {
    // Your routes
});

Route::get('/my-route', [MyController::class, 'method'])->name('my-route')->middleware('trusted');
bash
php artisan vendor:publish --tag="trusted-devices-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="trusted-devices-config"
bash
php artisan vendor:publish --tag="trusted-devices-views"