如何解决找不到类“ App \ Http \ Requests \ Web \ WebRequest”的问题

时间:2019-04-04 06:22:56

标签: laravel-5

我在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',
        ];
    }
}

这是我的Bucket Controller代码:

<?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');
}

请帮助我解决此错误。谢谢。

1 个答案:

答案 0 :(得分:1)

Requests文件夹中缺少我的WebRequest.php,这就是为什么他给了我这个错误。 这是我创建的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 [
        //
    ];
}
}