laravel-learn-bbs/app/Http/Controllers/Api/TopicsController.php
2018-06-10 18:35:53 +08:00

32 lines
878 B
PHP

<?php
namespace App\Http\Controllers\Api;
use App\Http\Requests\Api\TopicRequest;
use App\Models\Topic;
use App\Transformers\TopicTransformer;
class TopicsController extends Controller
{
public function store(TopicRequest $request, Topic $topic)
{
$topic->fill($request->all());
$topic->user_id = $this->user()->id;
$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());
}
}