40 lines
1022 B
PHP
40 lines
1022 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Requests;
|
||
|
|
|
||
|
|
use Illuminate\Foundation\Http\FormRequest;
|
||
|
|
|
||
|
|
class StoreGuestbookRequest extends FormRequest
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Determine if the user is authorized to make this request.
|
||
|
|
*/
|
||
|
|
public function authorize(): bool
|
||
|
|
{
|
||
|
|
return \Illuminate\Support\Facades\Auth::check(); // 必须登录
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the validation rules that apply to the request.
|
||
|
|
*
|
||
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||
|
|
*/
|
||
|
|
public function rules(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'towho' => 'nullable|string|max:50',
|
||
|
|
'secret' => 'sometimes|boolean',
|
||
|
|
'text_title' => 'nullable|string|max:250',
|
||
|
|
'text_body' => 'required|string|max:2000',
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function messages(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'text_body.required' => '留言内容不能为空!',
|
||
|
|
'text_body.max' => '留言内容不能超过 2000 个字符。',
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|