PHP code example of fk / laravel-utility

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

    

fk / laravel-utility example snippets


        

        use fk\utility\Database\Eloquent\Model;
        /** @var  \fk\utility\Database\Eloquent\Builder $model */
        $model = Model::find(1);
        $model->rawSql();
        // or simply call, witch applies the __toString method
        echo $model;
        

        

          \fk\utility\Database\Eloquent\Model::select(['alias' => ['fields']]);
        



class AppServiceProvider {
    
    public function register()
    {
        $this->app->register(\fk\utility\Session\SessionServiceProvider::class);
    }
}



[
    'providers' => [
        fk\utility\Session\SessionServiceProvider::class
    ]
];



# auth.php

return [
    'guards' => [
        'api' => [
            'driver' => 'easy.token',
            'model' => \App\Models\User::class, // The model to retrieve user from
        ]
    ]
];

    
    
    use \fk\utility\Foundation\Testing\TestCase;
    
    class YourTest extends TestCase
    {
        // Write your own `CreateApplication`
        // OR
        // Write a `createApplication` method here
        use CreateApplication;
    }
    

        
        
        namespace App\Http\Middleware;
        
        use fk\utility\Auth\Middleware\AclAuthenticate;
        
        class MyAuthenticate extends AclAuthenticate
        {
            public function authenticate(): bool
            {
                // Write your own authentication here
                // If false returned, a `Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException` exception will be thrown
                // otherwise, authentication will pass.
                // Feel free to throw any kind of exceptions that fits you
            }
        }
        

          
        
          class Kernel
          {
        
              protected $routeMiddleware = [
                  'auth.acl' => \App\Http\Middleware\MyAuthenticate::class,
              ];
          }
        

          
        
          Route::group(['middleware' => 'auth.acl'], function () {
              Route::get('sth', 'SomeController@someMethod');
              // ... stuff
          });
        
        

    # index.php, replace the default capture
    $response = $kernel->handle(
        $request = \fk\utility\Http\Request::capture()
    );
    
#
    # AppServiceProvider.php
    public function reigster()
    {
        $this->app->alias('request', \fk\utility\Http\Request::class);
    }