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])
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
27
app/Http/Resources/CategoryResource.php
Normal file
27
app/Http/Resources/CategoryResource.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class CategoryResource extends Resource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
// return parent::toArray($request);
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'code' => $this->code,
|
||||
'links' => [
|
||||
'self' => route('categories.show', ['categories' => $this->id])
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
29
app/Http/Resources/QuestionResource.php
Normal file
29
app/Http/Resources/QuestionResource.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class QuestionResource extends Resource
|
||||
{
|
||||
/**
|
||||
* Transform the resource collection into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
// return parent::toArray($request);
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'text' => $this->text,
|
||||
'number' => $this->number,
|
||||
'description' => $this->description,
|
||||
'section' => new SectionResource($this->section),
|
||||
'links' => [
|
||||
'self' => route('questions.show', ['questions' => $this->id])
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
28
app/Http/Resources/QuestionchoiceResource.php
Normal file
28
app/Http/Resources/QuestionchoiceResource.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class QuestionchoiceResource extends Resource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'number' => $this->number,
|
||||
'text' => $this->text,
|
||||
'fillable' => $this->fillable,
|
||||
'description' => $this->description,
|
||||
'links' => [
|
||||
'relatedTo' => route('questions.show', ['questions' => $this->question_id])
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
28
app/Http/Resources/QuestionnaireResource.php
Normal file
28
app/Http/Resources/QuestionnaireResource.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class QuestionnaireResource extends Resource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
// return parent::toArray($request);
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'category' => new CategoryResource($this->category),
|
||||
'title' => $this->title,
|
||||
'description' => $this->description,
|
||||
'links' => [
|
||||
'self' => route('questionnaires.show', ['questionnaires' => $this->id])
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
27
app/Http/Resources/RespondentResource.php
Normal file
27
app/Http/Resources/RespondentResource.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class RespondentResource extends Resource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'occupation' => $this->occupation,
|
||||
'gender' => $this->gender,
|
||||
'links' => [
|
||||
'self' => route('respondents.show', ['respondents' => $this->id])
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
27
app/Http/Resources/SectionResource.php
Normal file
27
app/Http/Resources/SectionResource.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class SectionResource extends Resource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
// return parent::toArray($request);
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'description' => $this->description,
|
||||
'links' => [
|
||||
'self' => route('sections.show', ['sections' => $this->id])
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
25
app/Http/Resources/UserResource.php
Normal file
25
app/Http/Resources/UserResource.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class UserResource extends Resource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
// return parent::toArray($request);
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'username' => $this->username,
|
||||
'name' => $this->name,
|
||||
'email' => $this->email
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user