Home > PHP Framework > Laravel > Integrate commonly used classes in laravel development into one package to avoid repeated copying and pasting every time

Integrate commonly used classes in laravel development into one package to avoid repeated copying and pasting every time

藏色散人
Release: 2020-09-17 09:22:10
forward
2259 people have browsed it

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

laravel-quick(github address: https://github.com/youyingxiang/laravel-quick.git) Encapsulates some common tools in our development to make development more efficient

  • Mainly includes translated language pack prompts for verification
  • According to Symfony\Component\HttpFoundation\Response for status Code interface format
  • Exception class processing
  • Integrate various cache operations based on redis
  • Service, repository, trait artisan command generation;

Installation

  • composer require yxx/laravel-quick
  • linux and mac
    php artisan vendor:publish --provider="Yxx\\LaravelQuick\\LaravelQuickServiceProvider"
  • windows
    php artisan vendor:publish --provider ="Yxx\LaravelQuick\LaravelQuickServiceProvider"

How to use

  • Exception usage example
    use Yxx\LaravelQuick\Exceptions\Api\ApiNotFoundException;// 请求参数错误throw new ApiRequestException();// 404 未找到throw new ApiNotFoundException();// 系统错误throw new ApiSystemException()// 未授权throw new ApiUnAuthException()自定义错误继承Yxx\LaravelQuick\Exceptions自己参照对应代码自定义
    Copy after login
  • api interface usage
    use Yxx\LaravelQuick\Traits\JsonResponseTrait// 成功return $this->success("消息",['name'=>"张三"]);// 失败return $this->error("错误");// 自定义return $this->apiResponse(Response::HTTP_BAD_GATEWAY,"502错误");
    Copy after login
  • The use of cache (encapsulates some methods of redis)
    use Yxx\LaravelQuick\Facades\CacheClient;CacheClient::hSet("test","1","张三");CacheClient::hGet("test","1");CacheClient::lPush("test","1");具体参考Yxx\LaravelQuick\Services\CacheService里面的方法....
    Copy after login

artisan command

  • Create Trait php artisan quick:create-trait test
  • Create Service php artisan quick:create-service Test/TestService
  • Create Repository 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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template