-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added like action to threads overview
- Loading branch information
Showing
4 changed files
with
61 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Resources\Json\JsonResource; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class ForumThreadResource extends JsonResource | ||
{ | ||
/** | ||
* Transform the resource into an array. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return array | ||
*/ | ||
public function toArray($request) | ||
{ | ||
$resource = [ | ||
'id' => $this->id, | ||
'title' => $this->title, | ||
'content' => $this->content, | ||
'locked' => (bool) $this->locked, | ||
'poster_user_id' => $this->user->id, | ||
'poster_username' => $this->user->username, | ||
'creation_date' => $this->created_at->format('Y-m-d H:i:s'), | ||
'reply_count' => $this->replies->count(), | ||
'score' => $this->likesDiffDislikesCount | ||
]; | ||
|
||
if(Auth::check()) | ||
$resource = array_merge($resource, $this->getUserSpecificDetails()); | ||
|
||
return $resource; | ||
} | ||
|
||
/** | ||
* Returns the user specific details for the resource. | ||
* | ||
* @return array | ||
*/ | ||
protected function getUserSpecificDetails() { | ||
$user = Auth::user(); | ||
|
||
return [ | ||
'current_user' => [ | ||
'like_action' => $user->likeAction($this->resource) | ||
] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters