Laravel 5 Validator错误:无法解析的依赖关系解析

时间:2015-04-03 12:36:24

标签: php ajax validation laravel

我遇到验证问题(至少我相信它是验证),在向我的控制器提交带有ajax的表单后,我收到以下错误:

Container.php第872行中的

BindingResolutionException: 不可解析的依赖关系解析类Illuminate \ Validation \ Validator中的[Parameter#1 [array $ data]]

结合此错误: 未捕获的TypeError:无法读取属性'长度'未定义的

我的控制器:

<?php namespace App\Http\Controllers;

use App\Http\Requests;
use Redirect;
use App\Http\Requests\ProductFormRequest;
use Illuminate\Validation\Validator;

class ContactController extends Controller {

public function contactProduct(ProductFormRequest $request, Validator $validator)
{
    if (!strlen($request->input('custom'))) {

        if ($validator->passes()) {
            \Mail::send('emails.order',
                $data = [
                    'firstname' => $request->get('firstname'),
                    'lastname'  => $request->get('lastname'),
                    'email'     => $request->get('email'),
                ], function ($message) use ($request) {
                    $message->from($request->get('email'));
                    $message->to('info@example.nl', 'example')
                            ->subject('example');
            });

            return $status = json_encode('success');
        }

        return $errors = json_encode($validator->errors()->all());
    }
}
}

我的申请文件:

<?php namespace App\Http\Requests;

use App\Http\Requests\Request;

class ProductFormRequest extends Request {

public function authorize()
{
    return true;
}


public function rules()
{
    return [
        'firstname' => 'required',
        'lastname'  => 'required',
        'email'     => 'required|email'
    ];
}

}

我现在已经尝试了很长时间,但无法弄清楚出了什么问题。所以任何帮助都将非常感谢!

0 个答案:

没有答案