noitran / lumen-form-requests by noitran

Missing form requests functionality for lumen, ported from laravel framework.
4,705
5
2
Package Data
Maintainer Username: noitran
Maintainer Contact: noitran.black@gmail.com (Noitran.Noitran)
Package Create Date: 2018-03-23
Package Last Update: 2020-02-10
Language: PHP
License: MIT
Last Refreshed: 2024-11-23 03:12:51
Package Statistics
Total Downloads: 4,705
Monthly Downloads: 2
Daily Downloads: 0
Total Stars: 5
Total Watchers: 2
Total Forks: 4
Total Open Issues: 0

lumen-form-requests

Missing form requests functionality for lumen, ported from laravel framework.

Installation

  • Install as composer package
composer require noitran/lumen-form-requests
  • Open your bootstrap/app.php and register as service provider
$app->register(Noitran\Form\Providers\FormRequestServiceProvider::class);

Usage

Refer to the official laravel documentation about form request usage

https://laravel.com/docs/5.7/validation#form-request-validation

Example Request

<?php

namespace App\Http\Requests;

use Noitran\Microservice\Foundation\Http\Requests\Request;

class CreateUserRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules(): array
    {
        $rules = [
            'email' => [
                'required',
                'email',
                'unique:users,email',
            ],
            'password' => [
                'required',
            ],
        ];
    }
}

Usage in Controller

<?php

namespace App\Http\Controllers;

use App\Http\Requests\CreateUserRequest;
use App\Http\Controllers\Controller;

class UsersController extends Controller
{
    /**
     * Store a new user.
     *
     * @param CreateUserRequest $request
     * @return Response
     */
    public function store(CreateUserRequest $request)
    {
        // store user
    }
}