如何在laravel 5中获取自定义错误页面?

时间:2016-01-28 05:49:18

标签: laravel-5

我需要获取示例404的自定义错误页面,而不是此错误this is the error that i get when we try to revisit this page after logging out

1 个答案:

答案 0 :(得分:-1)

https://laravel.com/docs/5.1/validation#custom-error-messages

如果需要,您可以使用自定义错误消息进行验证,而不是默认值。有几种方法可以指定自定义消息。首先,您可以将自定义消息作为第三个参数传递给Validator :: make方法:

$messages = [
    'required' => 'The :attribute field is required.',
];

$validator = Validator::make($input, $rules, $messages);

在此示例中,:attribute place-holder将替换为验证字段的实际名称。您还可以在验证消息中使用其他占位符。例如:

$messages = [
    'same'    => 'The :attribute and :other must match.',
    'size'    => 'The :attribute must be exactly :size.',
    'between' => 'The :attribute must be between :min - :max.',
    'in'      => 'The :attribute must be one of the following types: :values',
];

为给定属性指定自定义消息

有时您可能希望仅为特定字段指定自定义错误消息。您可以使用" dot"符号。首先指定属性的名称,然后是规则:

$messages = [
    'email.required' => 'We need to know your e-mail address!',
];

也要注意这一点: https://laracasts.com/series/laravel-5-fundamentals/episodes/12