Created API endpoints
This commit is contained in:
30
app/Http/Resources/AnswerResource.php
Normal file
30
app/Http/Resources/AnswerResource.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class AnswerResource extends Resource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'choice' => $this->questionchoice,
|
||||
'text' => $this->text,
|
||||
'links' => [
|
||||
'self' => route('answers.show', ['answers' => $this->id]),
|
||||
'relatedTo' => [
|
||||
'question' => route('questions.show', ['questions' => $this->question_id]),
|
||||
'respondent' => route('respondents.show', ['respondents' => $this->respondent_id])
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user