-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.larapi-template.stub
61 lines (43 loc) · 1.91 KB
/
controller.larapi-template.stub
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace {{ namespace }}\Controllers;
use {{ namespace }}\Requests\{{ resourceName }}ActualizarRequest;
use {{ namespace }}\Requests\{{ resourceName }}CrearRequest;
use {{ namespace }}\Services\{{ resourceName }}Service;
use App\Abstracts\Controller;
class {{ class }} extends Controller
{
private {{ resourceName }}Service ${{ partialVariableName }}Service;
public function __construct({{ resourceName }}Service ${{ partialVariableName }}Service)
{
$this->{{ partialVariableName }}Service = ${{ partialVariableName }}Service;
}
public function index()
{
$opciones = $this->parseResourceOptions();
$datosDevueltos = $this->{{ partialVariableName }}Service->obtenerTodos($opciones);
return $this->response($datosDevueltos);
}
public function show(${{ partialVariableName }}Id)
{
$opciones = $this->parseResourceOptions();
$datosDevueltos['{{ variableSnakeCase }}'] = $this->{{ partialVariableName }}Service->obtenerPorId(${{ partialVariableName }}Id, $opciones);
return $this->response($datosDevueltos);
}
public function store({{ resourceName }}CrearRequest $request)
{
$datos = $request->validated();
$datosDevueltos['{{ variableSnakeCase }}'] = $this->{{ partialVariableName }}Service->crear($datos);
return $this->response($datosDevueltos, 201);
}
public function update(${{ partialVariableName }}Id, {{ resourceName }}ActualizarRequest $request)
{
$datos = $request->validated();
$datosDevueltos['{{ variableSnakeCase }}'] = $this->{{ partialVariableName }}Service->actualizar(${{ partialVariableName }}Id, $datos);
return $this->response($datosDevueltos);
}
public function destroy(${{ partialVariableName }}Id)
{
$this->{{ partialVariableName }}Service->eliminar(${{ partialVariableName }}Id);
return $this->response(null, 204);
}
}