0
votes

We were using form request validation with Laravel. I'm trying to use the same requests with lumen, but it doesn't work as espected.

UserController

<?php

namespace App\Http\Controllers;

use App\Http\Requests\User\UserPostRequest;
use App\Macx\Logic\Interfaces\IUserLogic;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class UserController extends Controller
{
    private $userLogic;
    public function __construct(IUserLogic $userLogic)
    {
        $this->userLogic = $userLogic;
    }

    public function post(UserPostRequest $request)
    {
        return $this->userLogic->post(Auth::user(), $request->all());
    }
}

UserPostRequest

<?php

namespace App\Http\Requests\User;

use Illuminate\Support\Facades\Request;

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


        /**
         * Get the validation rules that apply to the request.
         *
         * @return array
         */
        public function rules()
        {
            return [
                'name'=>'required|min:3|max:255',
                'surname'=>'required|min:3|max:255',
                'email'=>'required|email|unique:companies',
            ];
        }
    }

But when I call /api/user/ with some post data I'm getting this error :

Call to undefined method App\Http\Requests\User\UserPostRequest::all()

Note: I have just saw that lumen doesn't support form request validation as described in documentation : https://lumen.laravel.com/docs/5.4/validation

Form requests are not supported by Lumen. If you would like to use form requests, you should use the full Laravel framework.

But this stuff is very useful, I'm still trying to find a good solution like form request validation.

2
did you run composer dump-autoload ?rogervila
no, I could find an info about that in documents. Lumen doesn't support form request validation. I'm trying to find a solution for this. Form requests are not supported by Lumen. If you would like to use form requests, you should use the full Laravel framework.fobus

2 Answers

4
votes

In General,Form requests are not supported by Lumen. If you would like to use form requests, you should use the full Laravel framework. enter link description here

Fortunately you can use https://github.com/ssi-anik/form-request in lumen.

0
votes

Lumen is an excellent micro-framework to do API-based projects. I have been doing multiple Lumen projects this year. Both clients and developers love it as it has the flexibility to work on REST API. If you are not familiar with Lumen already, it is the strip down version of Laravel which is built with speed as its target. Lumen contains most of the features found in Laravel, but in addition it also removes some features such as Session Driver which helps the framework to boost the speed. Lumen installation does not include sessions due to the fact that tokens are mostly used in an API based backend instead of sessions.

Follow this Link