stealthpro / lumen-form-request by Stealthpro

Form requests for Lumen Micro Framework, ported from Laravel Framework.
46
1
1
Package Data
Maintainer Username: Stealthpro
Maintainer Contact: av85.dev@gmail.com (Stealthpro)
Package Create Date: 2020-05-22
Package Last Update: 2020-05-22
Language: PHP
License: MIT
Last Refreshed: 2024-11-16 15:03:19
Package Statistics
Total Downloads: 46
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 1
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

lumen-form-requests

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