Home >PHP Framework >Laravel >Integrate commonly used classes in laravel development into one package to avoid repeated copying and pasting every time
The following tutorial column from Laravel will introduce to you how to integrate commonly used classes in development into a package to avoid repeated copying and pasting every time. I hope it will be useful to you. Friends in need help!
laravel-quick(github address: https://github.com/youyingxiang/laravel-quick.git) Encapsulates some common tools in our development to make development more efficient
composer require yxx/laravel-quick
php artisan vendor:publish --provider="Yxx\\LaravelQuick\\LaravelQuickServiceProvider"
php artisan vendor:publish --provider ="Yxx\LaravelQuick\LaravelQuickServiceProvider"
use Yxx\LaravelQuick\Exceptions\Api\ApiNotFoundException;// 请求参数错误throw new ApiRequestException();// 404 未找到throw new ApiNotFoundException();// 系统错误throw new ApiSystemException()// 未授权throw new ApiUnAuthException()自定义错误继承Yxx\LaravelQuick\Exceptions自己参照对应代码自定义
use Yxx\LaravelQuick\Traits\JsonResponseTrait// 成功return $this->success("消息",['name'=>"张三"]);// 失败return $this->error("错误");// 自定义return $this->apiResponse(Response::HTTP_BAD_GATEWAY,"502错误");
use Yxx\LaravelQuick\Facades\CacheClient;CacheClient::hSet("test","1","张三");CacheClient::hGet("test","1");CacheClient::lPush("test","1");具体参考Yxx\LaravelQuick\Services\CacheService里面的方法....
php artisan quick:create-trait test
php artisan quick:create-service Test/TestService
php artisan quick: create-repository Test
The above is the detailed content of Integrate commonly used classes in laravel development into one package to avoid repeated copying and pasting every time. For more information, please follow other related articles on the PHP Chinese website!