【发布时间】:2020-07-28 13:21:58
【问题描述】:
我遇到了自定义请求的问题。我用php artisan make:request StoreNewClient 创建了一个请求。
我已经在新的请求文件中配置了验证逻辑,比如:
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreNewClient extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return Auth::check();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [ ...
];
}
/**
* Get the error messages for the defined validation rules.
*
* @return array
*/
public function messages()
{
return [ ...
];
}
}
在控制器中,我导入了 use App\Http\Requests\StoreNewClient; 之类的文件,之后,在函数 store() 中我写了:
public function store(StoreNewClient $request)
{
// Will return only validated data
$validated = $request->validated();
...
}
这是我从文档中了解到的,但这给了我一个错误:Class App\Http\Requests\StoreNewClient does not exist but exists (!!)。
我已经尝试清除缓存并转储作曲家,但没有解决问题。有什么帮助吗?
【问题讨论】: