Skip to content
Snippets Groups Projects
Unverified Commit 7efca767 authored by Maxime FRIESS's avatar Maxime FRIESS :blue_heart:
Browse files

[api] Added products on movement

parent 8134ee5d
Branches
Tags 0.1.0
No related merge requests found
......@@ -28,12 +28,21 @@ class Controller extends BaseController
];
}
protected function commonIndex(Request $request, $class, $filters = [])
protected function commonIndex(Request $request, $class, $filters = [], $with = null)
{
if (is_array($request->ids)) {
return ["data" => $class::whereIn('id', $request->ids)->get()];
if ($with == null) {
return ["data" => $class::whereIn('id', $request->ids)->get()];
} else {
return ["data" => $class::with($with)->whereIn('id', $request->ids)->get()];
}
} else {
$data = $class::orderBy($request->order_by ?? 'id', $request->order_sort ?? 'asc');
if ($with == null) {
$data = $class::orderBy($request->order_by ?? 'id', $request->order_sort ?? 'asc');
} else {
$data = $class::with($with)->orderBy($request->order_by ?? 'id', $request->order_sort ?? 'asc');
}
if (is_array($request->filter)) {
foreach ($request->filter as $k => $v) {
if (array_key_exists($k, $filters)) {
......
......@@ -19,7 +19,7 @@ class MovementsController extends Controller
'name' => "like:name",
'rectification' => "equals:rectification",
'user_id' => "equals:user_id"
]);
], 'products');
}
/**
......@@ -30,7 +30,7 @@ class MovementsController extends Controller
*/
public function show($id)
{
return ['data' => Movement::with(['products', 'products.product'])->findOrFail($id)];
return ['data' => Movement::with(['products'])->findOrFail($id)];
}
public function store(Request $request)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment