修改话题
This commit is contained in:
parent
ef1a29cd40
commit
66a176b592
|
@ -15,4 +15,17 @@ class TopicsController extends Controller
|
|||
$topic->save();
|
||||
return $this->response->item($topic, new TopicTransformer())->setStatusCode(201);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TopicRequest $request
|
||||
* @param Topic $topic
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function update(TopicRequest $request, Topic $topic)
|
||||
{
|
||||
$this->authorize('update', $topic);
|
||||
$topic->update($request->all());
|
||||
return $this->response->item($topic, new TopicTransformer());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,11 +25,24 @@ class TopicRequest extends FormRequest
|
|||
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
case 'POSt':
|
||||
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 [];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function attributes()
|
||||
|
|
|
@ -9,6 +9,9 @@ use App\Observers\LinkObserver;
|
|||
use App\Observers\ReplyObserver;
|
||||
use App\Observers\TopicObserver;
|
||||
use Carbon\Carbon;
|
||||
use Dingo\Api\Facade\API;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
|
@ -39,5 +42,12 @@ class AppServiceProvider extends ServiceProvider
|
|||
if (app()->isLocal()) {
|
||||
$this->app->register(\VIACreative\SudoSu\ServiceProvider::class);
|
||||
}
|
||||
|
||||
API::error(function (ModelNotFoundException $exception) {
|
||||
abort(404);
|
||||
});
|
||||
API::error(function (AuthorizationException $exception) {
|
||||
abort(403, $exception->getMessage());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ $api = app('Dingo\Api\Routing\Router');
|
|||
|
||||
$api->version('v1', [
|
||||
'namespace' => 'App\Http\Controllers\Api',
|
||||
'middleware' => 'serializer:array',
|
||||
'middleware' => ['serializer:array', 'bindings'],
|
||||
], function ($api) {
|
||||
$api->group([
|
||||
'middleware' => 'api.throttle',
|
||||
|
@ -54,7 +54,7 @@ $api->version('v1', [
|
|||
});
|
||||
|
||||
// 需要 token 验证的接口
|
||||
$api->group(['middleware' => 'api.auth'], function ($api) {
|
||||
$api->group(['middleware' => 'api.auth',], function ($api) {
|
||||
// 当前登录用户信息
|
||||
$api->get('user', 'UsersController@me')
|
||||
->name('api.user.show');
|
||||
|
@ -66,6 +66,8 @@ $api->version('v1', [
|
|||
->name('api.user.update');
|
||||
//发布话题
|
||||
$api->post('topics', 'TopicsController@store')->name('api.topics.store');
|
||||
//发布话题
|
||||
$api->patch('topics/{topic}', 'TopicsController@update')->name('api.topics.update');
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user