laravel-5 - 如何解决找不到类“App\Http\Requests\Web\WebRequest”
问题描述
我在 App\Http\Requests\Web 中创建了一个请求,其中显示了错误。
找不到类“App\Http\Requests\Web\WebRequest”
这是我的请求 CreateBucket.php 的代码:
<?php
namespace App\Http\Requests\Web;
class CreateBucket extends WebRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'bucket_name' => 'required|string|string|max:30',
'bucket_type' => 'required|string|string|max:30',
'bucket_image' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg',
];
}
}
这是我的桶控制器代码:
<?php
namespace App\Http\Controllers\Web;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\Web\CreateBucket;
use App\Bucket;
class BucketController extends Controller
{
public function index(Request $request)
{
$buckets = Bucket::orderBy('id','ASC')->paginate(10);
return view('buckets.index',compact('buckets',$buckets))
->with('i',($request->input('page',1) - 1) * 10);
}
public function create()
{
return view('buckets.create');
}
public function store(CreateBucket $request)
{
if($request->hasFile('bucket_image')) {
$bucket_image = $request->file('bucket_image');
$bucket_image_name = time().'.'.$bucket_image->getClientOriginalExtension();
$path = public_path('Storage/BucketImages');
$bucket_image->move($path, $bucket_image_name);
$bucket_image = 'Storage/BucketImages/'.$bucket_image_name;
} else {
$bucket_image = NULL;
}
$category = Category::create([
'bucket_name' => $request->input('bucket_name'),
'bucket_image'=> $bucket_image,
'bucket_type' => $request->input('bucket_type'),
]);
return redirect()->route('buckets.index')
->with('success','Bucket created successfully');
}
请帮助我解决此错误。谢谢。
解决方案
我的 WebRequest.php 在 Requests 文件夹中丢失,这就是他给我这个错误的原因。这是我创建的 WebRequest.php 文件,我的问题已解决。
<?php
namespace App\Http\Requests\Web;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
class WebRequest extends FormRequest
{
/**
* 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 [
//
];
}
}
推荐阅读
- c - 无法释放结构
- virtual-machine - 是否可以对内部所有进程的虚拟机状态进行快照?
- javascript - 即使正则表达式匹配,Angular 模板驱动表单的字段也被视为无效
- database - 从本地连接 Azure DB 非常慢
- git - 运行“git pull”时,用于 Linux 的 Windows 子系统会导致 Windows 崩溃
- ios - CoreMotion 在 Swift Playgrounds 中不起作用
- javascript - 将当前参数传递给循环中的函数
- python - 在正则表达式中查找带有大写字母并以某个单词结尾的字符串
- python - python中的for循环出错..循环无法正常工作
- jquery - 将屏幕上的图像宽度更改为低于 600 像素但不高于 600 像素