PHP code example of saritasa / laravel-controllers

1. Go to this page and download the library: Download saritasa/laravel-controllers 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/ */

    

saritasa / laravel-controllers example snippets


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);
  }
}

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  
  });



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);
    }
}



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' => '

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');
  });
 vendor/bin/phpcs
 vendor/bin/phpcbf
 vendor/bin/phpunit