PHPackages                             saritasa/laravel-controllers - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. saritasa/laravel-controllers

AbandonedArchivedLibrary[API Development](/categories/api)

saritasa/laravel-controllers
============================

Saritasa controllers for typical operations

5.0.1(2y ago)617.8k↓33.3%4MITPHPPHP &gt;=8.0

Since Apr 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Saritasa/php-laravel-controllers)[ Packagist](https://packagist.org/packages/saritasa/laravel-controllers)[ RSS](/packages/saritasa-laravel-controllers/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (7)Versions (50)Used By (0)

Laravel Controllers
===================

[](#laravel-controllers)

[![PHP Unit](https://github.com/Saritasa/php-laravel-controllers/workflows/PHP%20Unit/badge.svg)](https://github.com/Saritasa/php-laravel-controllers/actions)[![PHP CodeSniffer](https://github.com/Saritasa/php-laravel-controllers/workflows/PHP%20Codesniffer/badge.svg)](https://github.com/Saritasa/php-laravel-controllers/actions)[![codecov](https://camo.githubusercontent.com/bbd31f20eb401704507e0bea4849f5e70a0039032fa63a4f36febd68495678a8/68747470733a2f2f636f6465636f762e696f2f67682f53617269746173612f7068702d6c61726176656c2d636f6e74726f6c6c6572732f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/Saritasa/php-laravel-controllers)[![Release](https://camo.githubusercontent.com/54b2fb8ba648bb4fcb82eb228f0105a987c51e731aabeb336676041ae6b3310d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f73617269746173612f7068702d6c61726176656c2d636f6e74726f6c6c6572732e737667)](https://github.com/Saritasa/php-laravel-controllers/releases)[![PHPv](https://camo.githubusercontent.com/25a8249ce1a7a1467c479468040eabd6be4279ae8aa6b39ec2ad783ddc098bdb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f73617269746173612f6c61726176656c2d636f6e74726f6c6c6572732e737667)](http://www.php.net)[![Downloads](https://camo.githubusercontent.com/0c068767de32ad6525e733a818bae5c491b1496ff315ffdcd0234af39bb5fe57/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73617269746173612f6c61726176656c2d636f6e74726f6c6c6572732e737667)](https://packagist.org/packages/saritasa/laravel-controllers)

Controllers for common UI and endpoints in Laravel,
like API authentication, password change, login page, etc.

Laravel 9.x/10.x
----------------

[](#laravel-9x10x)

Install the `saritasa/laravel-controllers` package:

```
$ composer require saritasa/laravel-controllers
```

Available 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](http://reactjs.com), [AngularJS](https://angularjs.org/), [VueJs](https://vuejs.org/), etc.
    API utilizes [Dingo/Api](https://github.com/dingo/api) library
    and custom extensions for it: [saritasa/dingo-api-custom](https://github.com/Saritasa/php-dingo-api-custom)

Controllers, described below, exist, but you must register routes for them manually

#### Methods

[](#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

[](#jwtauthapicontroller-authenticate-api-controller-uses-jwt-authentication)

Utilizes [Dingo\\Api JWT Auth](https://github.com/dingo/api/wiki/Authentication#json-web-tokens-jwt)
settings and underlying [tymon\\jwt-auth](https://github.com/tymondesigns/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

[](#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

[](#how-to-bind-iloginrequest-with-custom-request-class)

```
