Package Data | |
---|---|
Maintainer Username: | yelfive |
Package Create Date: | 2017-04-28 |
Package Last Update: | 2020-03-16 |
Language: | PHP |
License: | Unknown |
Last Refreshed: | 2025-02-09 15:01:56 |
Package Statistics | |
---|---|
Total Downloads: | 132 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Making laravel more practical
fk\utility\Database\Eloquent\Model
Add approach to get the sql to be executed. It's available by calling
<?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
Modify pagination
toArray
toFKStyle
Model::select related
Being able to using alias like following, see
\fk\utility\Database\Query\Builder::select
for more
<?php
\fk\utility\Database\Eloquent\Model::select(['alias' => ['fields']]);
fk\utility\Http\Request
public/index.php
# index.php, replace the default capture
$response = $kernel->handle(
$request = \fk\utility\Http\Request::capture()
);
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);
}
multipart/form-data
for method PUT
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.
<?php
class AppServiceProvider {
public function register()
{
$this->app->register(\fk\utility\Session\SessionServiceProvider::class);
}
}
<?php
[
'providers' => [
fk\utility\Session\SessionServiceProvider::class
]
];
Also remember cancel registering of the \Illuminate\Session\SessionServiceProvider
At last, you should set the config/session.php
add
'auto_start' => true,
Also, remember to disable Laravel's start-on-every-request feature by comment the following if exists
# 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
fk\utility\Auth\Session\SessionGuardServiceProvider
<?php
# auth.php
return [
'guards' => [
'api' => [
'driver' => 'easy.token',
'model' => \App\Models\User::class, // The model to retrieve user from
]
]
];
Class: fk\utility\Foundation\Testing\TestCase
Benefits: Output for json would be human readable for Chinese characters
Usage:
<?php
use \fk\utility\Foundation\Testing\TestCase;
class YourTest extends TestCase
{
// Write your own `CreateApplication`
// OR
// Write a `createApplication` method here
use CreateApplication;
}
Class: fk\utility\Auth\Middleware\AclAuthenticate
Usages:
Create your own authentication class to place your rules
<?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
<?php
class Kernel
{
protected $routeMiddleware = [
'auth.acl' => \App\Http\Middleware\MyAuthenticate::class,
];
}
Good to go. Define a route using middleware auth.acl
<?php
Route::group(['middleware' => 'auth.acl'], function () {
Route::get('sth', 'SomeController@someMethod');
// ... stuff
});