PHP code example of wamesk / laravel-auth

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

    

wamesk / laravel-auth example snippets


'providers' => [
    ...
    /*
     * Third Party Service Providers...
     */
    \Wame\LaravelAuth\LaravelAuthServiceProvider::class,
];



namespace App\Models;

use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Wame\LaravelAuth\Models\BaseUser;

class User extends BaseUser
{
    use HasUlids;

}

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],
    
    // Add lines below
    'api' => [
        'driver' => 'passport',
        'provider' => 'users',
    ],
],

'guard' => 'api', // Change value to 'api'

'password_grant_client' => [ // Password Grant Client - Login/Registration
    'id' => env('PASSPORT_PASSWORD_GRANT_CLIENT_ID'),
    'secret' => env('PASSPORT_PASSWORD_GRANT_CLIENT_SECRET'),
],

'personal_access_client' => [ // Personal Access Client - Social
    'id' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_ID'),
    'secret' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET'),
],

$table->bigIncrements('id');
$table->string('log_name')->nullable();
$table->text('description');
$table->nullableUlidMorphs('subject', 'subject'); // <-- Change to this value
$table->nullableUlidMorphs('causer', 'causer');   // <-- Change to this value
$table->json('properties')->nullable();
$table->timestamps();
$table->index('log_name');

 'order_column_name' => 'sort_order',



use Illuminate\Validation\Rules\Password;

return [
    
    // User Model
    'model' => \Wame\LaravelAuth\Models\BaseUser::class,

    /* Login Options */
    'login' => [

        // Determine if login should be possible.
        'enabled' => true,

        // Enable this if only verified users can log in.
        'only_verified' => false,

        // Additional parameters to login request
        'additional_body_params' => [
            // Example: 'app_version' => '
                ->symbols()
                ->uncompromised(),
            'confirmed'
        ],

        // Additional parameters to register request
        'additional_body_params' => [
            // Example: 'app_version' => '

class AuthController extends LaravelAuthController
{
    /*
    Here will be the documentation for register
    */
    
    public function register(Request $request): JsonResponse
    {
        return parent::register($request);
    }

    public function login(Request $request): JsonResponse
    {
        $return = parent::login($request);
        $data = $return->getData();

        $personal_number = User::whereId($data->data->user->id)->first()->personal_number;
        $data->data->user->personal_number = $personal_number;
        $return->setData($data);

        return $return;
    }

public function handle(UserCreatingEvent $event)
    {
        $user = $event->entity;
        
        $user->team_id = request()->team_id;
        $user->approve ?: $user->approve = 0;
    }
bash
php artisan wame:auth
bash
php artisan migrate
bash
php artisan passport:install
bash
php artisan vendor:publish --provider="Wame\LaravelAuth\LaravelAuthServiceProvider" --tag="views"
bash
php artisan vendor:publish --provider="Wame\LaravelAuth\LaravelAuthServiceProvider" --tag="translations"
bash
Route::controller(\App\Http\Controllers\v1\AuthController::class)->prefix('v1')->name('auth.')
    ->group(function () {

        if (config('wame-auth.register.enabled')) {
            Route::post('/register', 'register')->name('register');
        }

        if (config('wame-auth.login.enabled')) {
            Route::post('/login', 'login')->name('login');
            Route::middleware('auth:api')->post('/logout', 'logout')->name('logout');
        }

        if (config('wame-auth.email_verification.enabled')) {
            Route::post('/email/send_verification_link', 'sendVerificationLink')->name('verify.send_verification_link');
        }

        Route::post('/password/reset/send', 'sendPasswordReset')->name('password.reset.send');
        Route::post('/password/reset', 'validatePasswordReset')->name('password.reset');
        
        if (config('wame-auth.social.enabled')) {
            Route::post('/login/{provider}', 'socialLogin')->name('social-login');
        }
    });