PHP code example of little-superman / laravel-request-params
1. Go to this page and download the library: Download little-superman/laravel-request-params 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/ */
little-superman / laravel-request-params example snippets
[
'providers' => [
...,
LittleSuperman\RequestParams\Providers\ConfigServiceProvider::class,
LittleSuperman\RequestParams\Providers\ConsoleServiceProvider::class,
],
];
[
'whereSymbols' => [
//key => '对应前端传递值'
'and' => '&',
'or' => '|',
'equal' => '=',
'notEqual' => '!',
'greater' => '>',
'less' => '<',
'in' => '-',
'notIn' => '!-',
'between' => '<>',
'notBetewen' => '><',
'like' => '~',
'notLike' => '!=',
],
];
[
'orderSymbols' => [
//key => '对应前端传递值'
'asc' => 'asc',
'desc' => 'desc'
],
];
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use LittleSuperman\RequestParams\DynamicQuery\Query;
class User extends Model
{
//引入改特征
use Query;
/**
* 搜索字段
*
* @var array
*/
protected $searchField = [ //允许使用的字段
//前端使用的字段 => 数据库字段
'userId' => 'id',
];
}
User::queryable()->paginate();
User::queryable(User::class, ...)->get();
terminal
php artisan make:modle 模型名称
termianl
php artisan mkae:request 资源名称
text
$searchField = [
'userId' => 'id',
];