4
|
1 |
<?php |
|
2 |
|
|
3 |
namespace CorpusParole\Http\Controllers\Api; |
|
4 |
|
|
5 |
use Illuminate\Http\Request; |
|
6 |
|
|
7 |
use CorpusParole\Http\Requests; |
|
8 |
use CorpusParole\Http\Controllers\Controller; |
|
9 |
use CorpusParole\Repositories\DocumentRepository; |
|
10 |
|
|
11 |
class DocumentController extends Controller |
|
12 |
{ |
|
13 |
/** |
|
14 |
* Create a new controller instance. |
|
15 |
*/ |
|
16 |
public function __construct(DocumentRepository $documentRepo) { |
|
17 |
$this->documentRepository = $documentRepo; |
|
18 |
} |
|
19 |
|
|
20 |
/** |
|
21 |
* Display a listing of the resource. |
|
22 |
* |
|
23 |
* @return Response |
|
24 |
*/ |
|
25 |
public function index() |
|
26 |
{ |
20
|
27 |
$paginator = $this->documentRepository->paginateAll(); |
|
28 |
$res = []; |
|
29 |
foreach ($paginator->toArray() as $key => $value) { |
|
30 |
$res[($key === 'data')?'documents':$key] = $value; |
|
31 |
} |
|
32 |
return response()->json($res); |
4
|
33 |
} |
|
34 |
|
|
35 |
/** |
|
36 |
* Show the form for creating a new resource. |
|
37 |
* |
|
38 |
* @return Response |
|
39 |
*/ |
|
40 |
public function create() |
|
41 |
{ |
|
42 |
// |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* Store a newly created resource in storage. |
|
47 |
* |
|
48 |
* @param Request $request |
|
49 |
* @return Response |
|
50 |
*/ |
|
51 |
public function store(Request $request) |
|
52 |
{ |
|
53 |
// |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* Display the specified resource. |
|
58 |
* |
|
59 |
* @param int $id |
|
60 |
* @return Response |
|
61 |
*/ |
|
62 |
public function show($id) |
|
63 |
{ |
|
64 |
$doc = $this->documentRepository->get($id); |
|
65 |
if(is_null($doc)) { |
|
66 |
abort(404); |
|
67 |
} |
20
|
68 |
return response()->json(["document" => $doc]); |
4
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* Show the form for editing the specified resource. |
|
73 |
* |
|
74 |
* @param int $id |
|
75 |
* @return Response |
|
76 |
*/ |
|
77 |
public function edit($id) |
|
78 |
{ |
|
79 |
// |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* Update the specified resource in storage. |
|
84 |
* |
|
85 |
* @param Request $request |
|
86 |
* @param int $id |
|
87 |
* @return Response |
|
88 |
*/ |
|
89 |
public function update(Request $request, $id) |
|
90 |
{ |
|
91 |
// |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* Remove the specified resource from storage. |
|
96 |
* |
|
97 |
* @param int $id |
|
98 |
* @return Response |
|
99 |
*/ |
|
100 |
public function destroy($id) |
|
101 |
{ |
|
102 |
// |
|
103 |
} |
|
104 |
} |