你可能会看到我对 laravel 很陌生。我遇到了一个问题,它似乎无法看到我制作的新类(class)......
首先我跑了....
php artisan make:request CreateSongRequest
它又在 app/Http/Requests/中生成了一个 CreateSongRequest.php 文件
内容...
<?php namespace App\Http\Requests;
use App\Http\Requests\Request;
class CreateSongRequest 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 [
//
];
}
}
在我的 Controller 中,我将表单发布到以下方法...
public function store(CreateSongRequest $request, Song $song) {
$song->create($request->all());
return redirect()->route('songs_path');
}
当我提交表单时,出现以下错误...
RouteDependencyResolverTrait.php 第 53 行中的 ReflectionException:类 App\Http\Controllers\CreateSongRequest 不存在
最佳答案
您需要在 Controller 的顶部添加:
use App\Http\Requests\CreateSongRequest;
关于php - laravel 创建请求不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29102099/