Laravel表单请求验证问题

时间:2016-02-17 14:03:13

标签: laravel-5 laravel-5.2

我正在尝试在使用laravel 5.2构建的REST API中使用表单请求。我的控制器是

public function save(SbcEntityFormRequest $request)
{
        $requestData = Input::all();
        try {
            list($success, $message) = $this->sbcService->saveSbcEntity($requestData);
            if ($success) {
                return $this->successJsonResponse($request, ['id' => $message]);
            }

            return $this->errorJsonResponse($request, Response::HTTP_BAD_REQUEST, [$message]);
        } catch (Exception $e) {
            AppLog::write($e);
            $message = [config('messages.save_failed')];

            return $this->errorJsonResponse($request, Response::HTTP_BAD_REQUEST, $message);
        }
} 

我的表单请求是

namespace App\Http\Requests;

use Illuminate\Http\Request;
class SbcEntityFormRequest extends Request
{
    /**
     * 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 [
            'logo' => 'Required',
            'bio' => 'Required|Max:150'
        ];
    }
}

永远不会调用我的验证规则。我在authorize()函数中放了一个die语句,它既没有被调用。当我在控制器中打印$ request-> all()时,它显示空数组。关于这里有什么问题的任何想法?

0 个答案:

没有答案