exchange/app/Http/Controllers/Api/DocumentController.php

30 lines
850 B
PHP
Raw Normal View History

2022-11-29 10:54:43 +00:00
<?php
namespace App\Http\Controllers\Api;
use App\Models\Document;
use App\Transformers\DocumentTransformer;
2022-12-11 08:54:49 +00:00
use Illuminate\Http\Request;
2022-11-29 10:54:43 +00:00
class DocumentController extends ApiController
{
2022-12-11 08:54:49 +00:00
public function index(Request $request)
2022-11-29 10:54:43 +00:00
{
2022-12-11 08:54:49 +00:00
$page = $request->page ?? null;
2022-12-20 07:50:01 +00:00
$category = $request->category ?? null;
2022-12-11 08:54:49 +00:00
if($page){
2022-12-24 16:17:57 +00:00
$documents = Document::where('page', $page)->orderBy('lft', 'asc');
2022-12-20 07:50:01 +00:00
if(count($documents->get()) < 1){
2022-12-11 08:54:49 +00:00
return $this->errorNotFound();
}
}else{
2022-12-24 16:17:57 +00:00
$documents = Document::orderBy('lft', 'asc');
2022-12-11 08:54:49 +00:00
}
2022-12-20 07:50:01 +00:00
if($category){
$documents = $documents->where('document_category_id', $category);
}
return $this->respondWithCollection($documents->get(), new DocumentTransformer($this->locale));
2022-11-29 10:54:43 +00:00
}
}