2018-06-10 10:04:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Api;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class TopicRequest
|
|
|
|
* @property string title
|
|
|
|
* @property string body
|
|
|
|
* @property int category_id
|
|
|
|
* @package App\Http\Requests\Api
|
|
|
|
*/
|
|
|
|
class TopicRequest extends FormRequest
|
|
|
|
{
|
|
|
|
|
|
|
|
public function rules()
|
|
|
|
{
|
2018-06-10 10:35:53 +00:00
|
|
|
switch ($this->method()) {
|
2018-06-16 01:15:01 +00:00
|
|
|
case 'POST':
|
2018-06-10 10:35:53 +00:00
|
|
|
return [
|
|
|
|
'title' => 'required|string',
|
|
|
|
'body' => 'required|string',
|
|
|
|
'category_id' => 'required|exists:categories,id',
|
|
|
|
];
|
|
|
|
case 'PATCH':
|
|
|
|
return [
|
|
|
|
'title' => 'string',
|
|
|
|
'body' => 'string',
|
|
|
|
'category' => 'exists:categories,id'
|
|
|
|
];
|
|
|
|
default:
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-10 10:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attributes()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'title' => '标题',
|
|
|
|
'body' => '话题内容',
|
|
|
|
'category_id' => '分类',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|