saritasa/laravel-controllers
最新稳定版本:5.0.1
Composer 安装命令:
composer require saritasa/laravel-controllers
包简介
Saritasa controllers for typical operations
README 文档
README
Controllers for common UI and endpoints in Laravel,
like API authentication, password change, login page, etc.
Laravel 9.x/10.x
Install the saritasa/laravel-controllers package:
$ composer require saritasa/laravel-controllers
Available controllers
There are 2 types of controllers:
- Web - interactive UI for user - traditional Laravel controllers.
Many of them just provide out-of-the-box Laravel functionality,
using built-in traits. - Api - for programmatic integration with 3d party applications,
like mobile apps (iOS, Android) or single-page HTML applications,
built on modern frontend frameworks - React.JS, AngularJS, VueJs, etc.
API utilizes Dingo/Api library
and custom extensions for it: saritasa/dingo-api-custom
Controllers, described below, exist, but you must register routes for them manually
Methods
- function json($data, IDataTransformer $transformer = null): Response
Example:
class UserApiController extends BaseApiController { public function __construct(UserTransformer $userTransformer) { parent::__construct($userTransformer); } public function editUserProfile(Request $request, User $user): Response { $this->validate($request, $user->getRuels()); $user->fill($request->all()); $user->save(); return $this->json($user); } }
JWTAuthApiController Authenticate API Controller. Uses JWT authentication
Utilizes Dingo\Api JWT Auth
settings and underlying tymon\jwt-auth
Example: routes\api.php:
app('api.router')->version(config('api.version'), ['namespace' => 'Saritasa\Laravel\Controllers\Api'], function (\Dingo\Api\Routing\Router $api) { // Authentication $api->post('auth', 'AuthController@login'); // Login $api->put('auth', 'AuthController@refreshToken'); // Refresh expired token $api->delete('auth', 'AuthController@logout')->middleware('api.auth'); // Logout });
Customize login request
In some case, we're using email field for login with email or username in application. So, the email field should validation by required and string rule.
Or you want to use username instead of email.
How to bind ILoginRequest with custom request class
<?php namespace App\Providers; use App\Http\Requests\Auth\LoginRequest; use Illuminate\Support\Facades\URL; use Illuminate\Support\ServiceProvider; use Saritasa\LaravelControllers\Requests\Concerns\ILoginRequest; class AppServiceProvider extends ServiceProvider { public function boot() { $this->app->bind(ILoginRequest::class, LoginRequest::class); } }
<?php namespace App\Http\Requests\Auth; use Illuminate\Foundation\Http\FormRequest; use Saritasa\LaravelControllers\Requests\Concerns\ILoginRequest; class LoginRequest extends FormRequest implements ILoginRequest { /** * @inheritDoc */ public function rules(): array { return [ 'username' => 'required|string', 'password' => 'required|string', ]; } }
ForgotPasswordApiController, ResetPasswordApiController These controllers are responsible for handling password reset emails.
Utilize native Laravel password management without UI, in JSON API.
Example: routes\api.php:
app('api.router')->version(config('api.version'), ['namespace' => 'Saritasa\Laravel\Controllers\Api'], function (\Dingo\Api\Routing\Router $api) { $api->post('auth/password/reset', 'ForgotPasswordApiController@sendResetLinkEmail'); $api->put('auth/password/reset', 'ResetPasswordApiController@reset'); });
Contributing
- Create fork, checkout it
- Develop locally as usual. Code must follow PSR-1, PSR-2 -
run PHP_CodeSniffer to ensure, that code follows style guides - Cover added functionality with unit tests and run PHPUnit to make sure, that all tests pass
- Update README.md to describe new or changed functionality
- Add changes description to CHANGES.md file. Use Semantic Versioning convention to determine next version number.
- When ready, create pull request
Make shortcuts
If you have GNU Make installed, you can use following shortcuts:
make cs(instead ofphp vendor/bin/phpcs) -
run static code analysis with PHP_CodeSniffer
to check code stylemake csfix(instead ofphp vendor/bin/phpcbf) -
fix code style violations with PHP_CodeSniffer
automatically, where possible (ex. PSR-2 code formatting violations)make test(instead ofphp vendor/bin/phpunit) -
run tests with PHPUnitmake install- instead ofcomposer install*make allor justmakewithout parameters -
invokes described above install, cs, test tasks sequentially -
project will be assembled, checked with linter and tested with one single command
Resources
saritasa/laravel-controllers 适用场景与选型建议
saritasa/laravel-controllers 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.81k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2017 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「restful」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 saritasa/laravel-controllers 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 saritasa/laravel-controllers 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 saritasa/laravel-controllers 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
This is a restful api to onesignal.
A RESTful API package for the Laravel and Lumen frameworks.
Alfabank REST API integration
Simple and lightweight HTTP client based cURL
RESTful API server for structured and self-documenting resources over JSON, XML, ...
统计信息
- 总下载量: 17.81k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-04-07