PHP code example of calject / laravel-productivity
1. Go to this page and download the library: Download calject/laravel-productivity 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/ */
calject / laravel-productivity example snippets
/*
|--------------------------------------------------------------------------
| 自定义字段验证规则
|--------------------------------------------------------------------------
| 自定义字段验证规则
|
*/
'rules' => [
/* ======== 接口参数规则定义 ======== */
'username' => 'riods' => '
$rules = Rules::get(['username', 'id_card'])->rules();
/** 生成结果:
array:4 [▼
"username" => "obile" => " 'value1' => 'ame" => "obile" => "▼
"value1" => "
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->mapApiRoutes();
$this->mapCreditRoutes();
$this->mapDevelopRoutes();
$this->mapTestRoutes();
// 添加注解实现
$annotationRoute = new AnnotationRoute();
// $annotationRoute->envs('local'); // 设置生效环境
// $annotationRoute->envs(['local', 'develop']); // 设置生效环境
$annotationRoute->mapRefRoutes();
}
namespace App\Http\Controllers\Test;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
/**
* Class TestRouterController
* @package App\Http\Controllers\Test
* @route(prefix='test', middleware='api,mid,mid2')
*/
class TestController extends Controller
{
/**
* @param Request $request
* @return ResponseFactory|Response
* @api('testA')
* @name(testA)
*/
public function testA(Request $request)
{
return response('testA');
}
/**
* @param Request $request
* @return ResponseFactory|Response
* @route(api='testD', method='get,post,put', name='testD')
* @middleware(testD)
*/
public function testD(Request $request)
{
return response('testD');
}
}
/**
* Class AnnotationRoute
* @package Calject\LaravelProductivity\Components\Routes
* ---------- set ----------
* @method $this setEnvs($envs) 生效环境
* @method $this setControllers($controllers) 注解查询的路径[相对路径]
*
* ---------- get ----------
* @method mixed getEnvs() 生效环境
* @method mixed getControllers() 注解查询的路径[相对路径]
*
* ---------- apt ----------
* @method $this|mixed envs($envs = null) 生效环境
* @method $this|mixed controllers($controllers = null) 注解查询的路径[相对路径]
*/
class AnnotationRoute extends CallDataProperty
{
use TCallDataPropertyByName;
/**
* @var string
*/
private $namespace = 'App\Http\Controllers';
/**
* @note 生效环境
* @var mixed
* @explain array|string 传入数组或者字符 默认为所有环境生效
* @example local 、 produce 、 ['local', 'develop'] 、 ...
*/
protected $envs;
/**
* @note 注解查询的路径(相对路径)
* @var mixed
* @explain array|string 传入数组或者字符 默认为空查询app/Http/Controllers下所有控制器文件
* @example Test 、 User 、['Test'、 'User'] 、 ...
*/
protected $controllers;
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* Class TestModel
* @property int $id id
* @property string $order_no 订单
* @property int $amount 金额
* @property int $channel_id 渠道
* @property int $status 状态: 1.xxx 2.xxx
* @property string $created_at
* @property string $updated_at
* @property string $deleted_at
* @package App\Models
*/
class TestModel extends Model
{
protected $table = 'test';
}
return [
'APP_NAME' => env('APP_NAME'),
'APP_ENV' => env('APP_ENV'),
'APP_KEY' => env('APP_KEY'),
'APP_DEBUG' => env('APP_DEBUG'),
'APP_URL' => env('APP_URL'),
'RECEIVE_URL' => env('RECEIVE_URL'),
'LOG_CHANNEL' => env('LOG_CHANNEL'),
'DB_CONNECTION' => env('DB_CONNECTION'),
'DB_HOST' => env('DB_HOST'),
'DB_PORT' => env('DB_PORT'),
'DB_USERNAME' => env('DB_USERNAME'),
'DB_PASSWORD' => env('DB_PASSWORD'),
'DB_PREFIX' => env('DB_PREFIX'),
'DB_DATABASE_PAYMENT' => env('DB_DATABASE_PAYMENT'),
'DB_DATABASE_PUBLIC' => env('DB_DATABASE_PUBLIC'),
'BROADCAST_DRIVER' => env('BROADCAST_DRIVER'),
'CACHE_DRIVER' => env('CACHE_DRIVER'),
'SESSION_DRIVER' => env('SESSION_DRIVER'),
'QUEUE_DRIVER' => env('QUEUE_DRIVER'),
'ELASTIC_HOST' => env('ELASTIC_HOST'),
'ELASTIC_LOG_INDEX' => env('ELASTIC_LOG_INDEX'),
'ELASTIC_LOG_TYPE' => env('ELASTIC_LOG_TYPE'),
'REDIS_HOST' => env('REDIS_HOST'),
'REDIS_PASSWORD' => env('REDIS_PASSWORD'),
'REDIS_PORT' => env('REDIS_PORT'),
'MAIL_DRIVER' => env('MAIL_DRIVER'),
'MAIL_HOST' => env('MAIL_HOST'),
'MAIL_PORT' => env('MAIL_PORT'),
'MAIL_USERNAME' => env('MAIL_USERNAME'),
'MAIL_PASSWORD' => env('MAIL_PASSWORD'),
'MAIL_ENCRYPTION' => env('MAIL_ENCRYPTION'),
'PUSHER_APP_ID' => env('PUSHER_APP_ID'),
'PUSHER_APP_KEY' => env('PUSHER_APP_KEY'),
'PUSHER_APP_SECRET' => env('PUSHER_APP_SECRET'),
'PUSHER_APP_CLUSTER' => env('PUSHER_APP_CLUSTER'),
'MIX_PUSHER_APP_KEY' => env('MIX_PUSHER_APP_KEY'),
'MIX_PUSHER_APP_CLUSTER' => env('MIX_PUSHER_APP_CLUSTER'),
];
+-------+-------------------+-----------------------------------------------------------+
| queue | class | path |
+-------+-------------------+-----------------------------------------------------------+
| call | App\Jobs\TestJob | /Users/kaka/sites/calject/la-server/app/Jobs/TestJob.php |
| back | App\Jobs\TestJob2 | /Users/kaka/sites/calject/la-server/app/Jobs/TestJob2.php |
| | App\Jobs\TestJob3 | /Users/kaka/sites/calject/la-server/app/Jobs/TestJob3.php |
| | App\Jobs\TestJob4 | /Users/kaka/sites/calject/la-server/app/Jobs/TestJob4.php |
+-------+-------------------+-----------------------------------------------------------+