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

时间:2017-12-19 04:09:33

标签: php laravel-5.5

我已经为验证创建了自定义请求类。但它显示我的请求类不存在。我使用artisan命令创建了请求类。

php artisan make:request JobDetailRequest

这是我的请求类

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

这是我的控制器,我使用自定义验证请求

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

}

}

我也尝试过 composer dump-autoload 。但它无效。

3 个答案:

答案 0 :(得分:1)

我在Laravel 5.6中有一个类似的错误。原来我在自定义Http请求文件中有一个错误(缺少括号)。该文件没有显示错误,而没有显示错误。

一旦我修复了文件中的错误,就加载了类并修复了错误。

我希望这会对以后遇到此问题的任何人有所帮助。

答案 1 :(得分:0)

请在JobDetailRequest

中添加
  use Illuminate\Http\Request as BaseRequest;

使用此链接Link-1Link-2

谢谢

答案 2 :(得分:0)

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

}

也许你错过了一个" {"和" }"在JobDetailRequest类中。请试试这个。