PHP code example of chivincent / laravel-kratos

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

    

chivincent / laravel-kratos example snippets




return [
    // ...
    'guards' => [
        'kratos' => [
            'driver' => 'kratos',
            'provider' => 'kratos', // or 'kratos-database'
        ],    
    ],
    // ...
];



return [
    // ...
    
    'allowed_origins' => ['http://127.0.0.1:4455'], // Port 4455 is the default application of Kratos Frontend UI
    
    // ...
    
    'supports_credentials' => true,
    
    // ...
]; 



return [
    // ...
    'connections' => [
        'kratos' => [ // connection name should as same as `config('kratos.user_providers.kratos-database.connection')` 
            'driver' => 'pgsql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_KRATOS_DATABASE', 'kratos'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
            'search_path' => 'public',
            'sslmode' => 'prefer',
        ],    
    ]
    // ... 
];

// app/Models/User.php

use Chivincent\LaravelKratos\Models\KratosIdentity;
use Chivincent\LaravelKratos\Models\KratosUser;
use Illuminate\Contracts\Auth\MustVerifyEmail;

// If using "kratos" user provider:
class User extends KratosIdentity implements MustVerifyEmail
{
}

// If using "kratos-database" user provider:
//class User extends KratosUser implements MustVerifyEmail
//{
//}

Route::middleware('auth:kratos')
    ->get('user', fn (Request $request) => response()->json($request->user()));
shell
php artisan vendor:publish --provider="Chivincent\LaravelKratos\KratosServiceProvider"