简体   繁体   English

错误:laravel 5.5中不存在请求类

[英]Error: request class does not exist in laravel 5.5

i have created the custom request class for validation .but it showing me request class doesn't exist. 我已经创建了用于验证的自定义请求类。但是它向我显示请求类不存在。 i have created request class using artisan command. 我已经使用工匠命令创建了请求类。

php artisan make:request JobDetailRequest

this is my request class 这是我的要求课

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class JobDetailRequest extends FormRequest
/**
 * Determine if the user is authorized to make this request.
 *
 * @return bool
 */
public function authorize()
{
    return false;
}

/**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules()
{
    return [
        'jobtitle' => 'bail|required|max:100',
        'jobdescription' => 'required',
        'experange' => 'required',
        'qualification' => 'required',
        'joblocation' => 'required',
    ];
}

 public function messages()
{
    return [
        'jobtitle.required'=>'Job title field required',
        'jobdescription.required'=>'Job description field required',
        'experange.required'=>'experience field required',
        'qualification.required'=>'Qualification required',
        'joblocation.required'=>'job location required'
    ];
} 

this is my controller where im using custom request for validation 这是我的控制器,即时通讯使用自定义请求进行验证

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\JobDetailRequest;
use App\job_detail;



class jobDetailController extends Controller
{
//
public function __construct()
{
}

public function index()
{
    return view('admin.job_details');
}

public function store(JobDetailRequest $request)
{


    $jobTitle=$request->jobtitle;
    $jobDesc=$request->jobdescription;
    $exp=$request->experange;
    $qualf=$request->qualification;
    $loc=$request->joblocation;

    $jobdetails=new job_detail;
    $jobdetails->title=$jobTitle;
    $jobdetails->desc=$jobDesc;
    $jobdetails->exp=$exp;
    $jobdetails->qualification=$qualf;
    $jobdetails->location=$loc;
    $jobdetails->save();
    return back()->with('status','Your Job details saved successfully');

}

} }

i also tried composer dump-autoload .but its not working. 我还尝试了作曲家dump-autoload,但无法正常工作。

I had a similar error in Laravel 5.6. 我在Laravel 5.6中有一个类似的错误。 It turned out I had a error (a missing bracket) in the custom Http Request file. 原来我在自定义Http请求文件中有一个错误(缺少括号)。 Rather than showing an error the file simply wasn't loading. 并没有显示错误,只是没有加载该文件。

Once I fixed the error in the file, the class was loaded and the error fixed. 一旦我修复了文件中的错误,便会加载该类并修复该错误。

I hope this helps anyone who comes across this in future. 我希望这对以后遇到此问题的任何人有所帮助。

please add this in JobDetailRequest 请在JobDetailRequest中添加

  use Illuminate\Http\Request as BaseRequest;

use this link Link-1 and Link-2 使用此链接Link-1Link-2

Thank You 谢谢

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class JobDetailRequest extends FormRequest {

    public function authorize() {
        return false;
    }

    public function rules() {
        return [
            'jobtitle' => 'bail|required|max:100',
            'jobdescription' => 'required',
            'experange' => 'required',
            'qualification' => 'required',
            'joblocation' => 'required',
        ];
    }

    public function messages() {
        return [
            'jobtitle.required'=>'Job title field required',
            'jobdescription.required'=>'Job description field required',
            'experange.required'=>'experience field required',
            'qualification.required'=>'Qualification required',
            'joblocation.required'=>'job location required'
        ];
    }

}

Maybe you are missing a " { " and " } " in your JobDetailRequest class. 也许您的JobDetailRequest类中缺少“ {”和“}”。 Please try this instead. 请改用此方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM