mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
feat: ✨ Supporto alle relations included
This commit is contained in:
@@ -17,9 +17,10 @@ class ApiController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*/
|
*/
|
||||||
public function index(): ResourceCollection
|
public function index(Request $request): ResourceCollection
|
||||||
{
|
{
|
||||||
return new ResourceCollection($this->model::all());
|
return (new ResourceCollection($this->model::all()))
|
||||||
|
->include(explode(',', $request->input('include')));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,7 +39,7 @@ class ApiController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Display the specified resource.
|
* Display the specified resource.
|
||||||
*/
|
*/
|
||||||
public function show(int $id): Resource|JsonResponse
|
public function show(int $id, Request $request): Resource|JsonResponse
|
||||||
{
|
{
|
||||||
$instance = $this->model::find($id);
|
$instance = $this->model::find($id);
|
||||||
|
|
||||||
@@ -46,7 +47,8 @@ class ApiController extends Controller
|
|||||||
return $this->error(Response::HTTP_NOT_FOUND, __('Risorsa non trovata.'));
|
return $this->error(Response::HTTP_NOT_FOUND, __('Risorsa non trovata.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Resource($instance);
|
return (new Resource($instance))
|
||||||
|
->include(explode(',', $request->input('include')));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -73,7 +73,8 @@ export class RecordsPage extends Page {
|
|||||||
|
|
||||||
async oninit(vnode: Vnode) {
|
async oninit(vnode: Vnode) {
|
||||||
super.oninit(vnode);
|
super.oninit(vnode);
|
||||||
const response = await this.model.all();
|
// @ts-ignore
|
||||||
|
const response = await this.model.with(this.model.relationships).get();
|
||||||
const data = response.getData() as Model[];
|
const data = response.getData() as Model[];
|
||||||
|
|
||||||
if (data.length > 0) {
|
if (data.length > 0) {
|
||||||
@@ -152,7 +153,7 @@ export class RecordsPage extends Page {
|
|||||||
|
|
||||||
async updateRecord(id: number) {
|
async updateRecord(id: number) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const response = await this.model.find(id);
|
const response = await this.model.with(this.model.relationships).find(id);
|
||||||
const instance = response.getData() as IModel;
|
const instance = response.getData() as IModel;
|
||||||
const dialog = $('mwc-dialog#add-record-dialog');
|
const dialog = $('mwc-dialog#add-record-dialog');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user