Skip to content

Commit

Permalink
Merge branch 'release/6.0.13'
Browse files Browse the repository at this point in the history
* release/6.0.13:
  fixes #880
  fixes #879
  • Loading branch information
austintoddj committed Nov 1, 2020
2 parents a653ea6 + 7f71392 commit bda0d99
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ public function store(StorePostRequest $request, $id): JsonResponse
{
$data = $request->validated();

if ($request->user('canvas')->isAdmin) {
$post = Post::with('tags', 'topic')->find($id);
} else {
$post = Post::with('tags', 'topic')->where('user_id', $request->user('canvas')->id)->find($id);
}
$post = Post::when($request->user('canvas')->isContributor, function ($query) {
return $query->where('user_id', request()->user('canvas')->id);
}, function ($query) {
return $query;
})->with('tags', 'topic')->find($id);

if (! $post) {
$post = new Post(['id' => $id]);
}

$post->fill($data);

$post->user_id = $request->user('canvas')->id;
$post->user_id = $post->user_id ?? request()->user('canvas')->id;

$post->save();

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function store(StoreTagRequest $request, $id): JsonResponse

$tag->fill($data);

$tag->user_id = request()->user('canvas')->id;
$tag->user_id = $tag->user_id ?? request()->user('canvas')->id;

$tag->save();

Expand Down
20 changes: 10 additions & 10 deletions src/Http/Controllers/TopicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,25 @@ public function store(StoreTopicRequest $request, $id): JsonResponse
{
$data = $request->validated();

$tag = Topic::find($id);
$topic = Topic::find($id);

if (! $tag) {
if ($tag = Topic::onlyTrashed()->firstWhere('slug', $data['slug'])) {
$tag->restore();
if (! $topic) {
if ($topic = Topic::onlyTrashed()->firstWhere('slug', $data['slug'])) {
$topic->restore();

return response()->json($tag->refresh(), 201);
return response()->json($topic->refresh(), 201);
} else {
$tag = new Topic(['id' => $id]);
$topic = new Topic(['id' => $id]);
}
}

$tag->fill($data);
$topic->fill($data);

$tag->user_id = request()->user('canvas')->id;
$topic->user_id = $topic->user_id ?? request()->user('canvas')->id;

$tag->save();
$topic->save();

return response()->json($tag->refresh(), 201);
return response()->json($topic->refresh(), 201);
}

/**
Expand Down

0 comments on commit bda0d99

Please sign in to comment.