2017 © Pedro Peláez
 

library laravel-utility

Making laravel more practical

image

fk/laravel-utility

Making laravel more practical

  • Sunday, January 21, 2018
  • by yelfive
  • Repository
  • 1 Watchers
  • 1 Stars
  • 43 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 17 Versions
  • 0 % Grown

The README.md

Utilities

Making laravel more practical, (*1)

Database

Model

  • Usage: Just extends fk\utility\Database\Eloquent\Model
  • functionality, (*2)

    • Add approach to get the sql to be executed. It's available by calling, (*3)

      <?php
      
      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;
      

      In fact, it works for any method that returns a fk\utility\Database\Eloquent\Builder, (*4)

    • Modify pagination, (*5)

      • add access to custom fields when calling toArray
      • add access to toFKStyle
    • Model::select related, (*6)

      Being able to using alias like following, see \fk\utility\Database\Query\Builder::select for more, (*7)

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

Request

  • Class
    • fk\utility\Http\Request
  • Usage
    • Capture at public/index.php # index.php, replace the default capture $response = $kernel->handle( $request = \fk\utility\Http\Request::capture() );
    • Extends or use it for IOC
    • Register it's alias as request, to ensure every instance fallback to the singleton instance used to capture at entry index.php # # AppServiceProvider.php public function reigster() { $this->app->alias('request', \fk\utility\Http\Request::class); }
  • Functionality
    • Add support for Content-Type multipart/form-data for method PUT

Session

Allow session to be actually applied just when called. Not when requested. This is useful for RESTFul APIs, for some doesn't need a session., (*8)

AppServiceProvider

<?php

class AppServiceProvider {

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

or add to config/app.php

<?php

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

Also remember cancel registering of the \Illuminate\Session\SessionServiceProvider, (*9)

At last, you should set the config/session.php add, (*10)

'auto_start' => true,

Also, remember to disable Laravel's start-on-every-request feature by comment the following if exists, (*11)

# app\Http\Kernel

public $middlewares = [
//    \Illuminate\Session\Middleware\StartSession::class,
]

If you have your own rule of session id, you can overwrite the \fk\utility\Session\SessionServiceProvider::getAccessToken to achieve that, (*12)

Easy Authentication

Register Service Provider

fk\utility\Auth\Session\SessionGuardServiceProvider, (*13)

Config

<?php

# auth.php

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

PHPUnit

TestCase

  • Class: fk\utility\Foundation\Testing\TestCase
  • Benefits: Output for json would be human readable for Chinese characters
  • Usage:, (*14)

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

ACL Check

  • Class: fk\utility\Auth\Middleware\AclAuthenticate
  • Usages:, (*15)

    • Create your own authentication class to place your rules, (*16)

      <?php
      
      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
          }
      }
      
    • Register at App\Http\Kernel, (*17)

        <?php
      
        class Kernel
        {
      
            protected $routeMiddleware = [
                'auth.acl' => \App\Http\Middleware\MyAuthenticate::class,
            ];
        }
      
    • Good to go. Define a route using middleware auth.acl, (*18)

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

The Versions

21/01 2018

dev-dev

dev-dev

Making laravel more practical

  Sources   Download

The Requires

 

21/01 2018

v2.0.16

2.0.16.0

Making laravel more practical

  Sources   Download

The Requires

 

15/01 2018

v2.0.15

2.0.15.0

Making laravel more practical

  Sources   Download

The Requires

 

15/01 2018

v2.0.14

2.0.14.0

Making laravel more practical

  Sources   Download

The Requires

 

15/01 2018

v2.0.13

2.0.13.0

Making laravel more practical

  Sources   Download

The Requires

 

15/01 2018

v2.0.12

2.0.12.0

Making laravel more practical

  Sources   Download

The Requires

 

10/01 2018

v2.0.11

2.0.11.0

Making laravel more practical

  Sources   Download

The Requires

 

28/12 2017

v2.0.8

2.0.8.0

Making laravel more practical

  Sources   Download

The Requires

 

20/12 2017

v2.0.7

2.0.7.0

Making laravel more practical

  Sources   Download

The Requires

 

19/12 2017

v2.0.6

2.0.6.0

Making laravel more practical

  Sources   Download

The Requires

 

12/12 2017

v2.0.5

2.0.5.0

Making laravel more practical

  Sources   Download

The Requires

 

11/12 2017

v2.0.4

2.0.4.0

Making laravel more practical

  Sources   Download

The Requires

 

10/12 2017

v2.0.3

2.0.3.0

Making laravel more practical

  Sources   Download

The Requires

 

08/12 2017

v2.0.2

2.0.2.0

Making laravel more practical

  Sources   Download

The Requires

 

05/12 2017

v2.0.1

2.0.1.0

Making laravel more practical

  Sources   Download

The Requires

 

04/12 2017

dev-master

9999999-dev

Making laravel more practical

  Sources   Download

The Requires

 

04/12 2017

v2.0

2.0.0.0

Making laravel more practical

  Sources   Download

The Requires