stealthpro/lumen-form-request

Form requests for Lumen Micro Framework, ported from Laravel Framework.

0.0.2 2020-05-22 12:46 UTC

This package is auto-updated.

Last update: 2024-11-22 23:05:23 UTC


README

Software License Latest Version Total Downloads

Form requests for Lumen Micro Framework, ported from Laravel Framework.

Support Lumen versions: 5.6+, 6.0+, 7.0+

Installation

  • Install as composer package
composer require stealthpro/lumen-form-request
  • Open your bootstrap/app.php and register as service provider
$app->register(Stealthpro\LumenFormRequest\Providers\FormRequestServiceProvider::class);

Usage

Refer to the official laravel documentation about form request usage

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

Example Request

<?php

namespace App\Http\Requests;

use Stealthpro\LumenFormRequest\Http\FormRequest;

class PostRequest extends FormRequest
{
    /**
     * 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
    {
        return [
            'title' => [
                'required',
                'string',
                'max:255',
                'unique:posts,title',
            ],
            'description' => 'required|string',
        ];
    }
}

Usage in Controller

<?php

namespace App\Http\Controllers;

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

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