Skip to content

Commit

Permalink
fix(feed): ( issue #324 ) 修复更新控制器代码使用不存在的对象
Browse files Browse the repository at this point in the history
  • Loading branch information
medz committed Jul 25, 2018
1 parent 7a9e2d0 commit f36c6e2
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions app/API2/Controllers/Feed/Topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,11 @@ public function create(CreateTopicRequest $request, ModelsTypes $types): JsonRes
* Edit an topic.
*
* @param \Zhiyi\Plus\API2\Requests\Feed\EditTopic $request
* @param \Zhiyi\Plus\Types\Models $types
* @param \Zhiyi\Plus\Models\FeedTopic $topic
* @return \Illuminate\Http\Response
*/
public function update(EditTopicRequest $request, FeedTopicModel $topic): Response
public function update(EditTopicRequest $request, ModelsTypes $types, FeedTopicModel $topic): Response
{
$this->authorize('update', $topic);

Expand All @@ -208,18 +209,14 @@ public function update(EditTopicRequest $request, FeedTopicModel $topic): Respon
}

$with->user_id = $request->user()->id;
$with->channel = $types->get(FeedTopicModel::class, ModelsTypes::KEY_BY_CLASSNAME);
$with->raw = $topic->id;
}

$topic->desc = $desc ?: $topic->desc;

return $topic->getConnection()->transaction(function () use ($response, $topic, $with): Response {
if ($with instanceof FileWithModel) {
if ($topic->logo) {
$with->query()->where('id', $topic->logo)->delete();
}

$with->channel = $types->get(FeedTopicModel::class, ModelsTypes::KEY_BY_CLASSNAME);
$with->raw = $topic->id;
$with->save();

// Set file with ID to topic logo.
Expand Down

0 comments on commit f36c6e2

Please sign in to comment.