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.
composer dump-autoload
? – rogervila