30 lines
850 B
PHP
30 lines
850 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Models\Document;
|
|
use App\Transformers\DocumentTransformer;
|
|
use Illuminate\Http\Request;
|
|
|
|
class DocumentController extends ApiController
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$page = $request->page ?? null;
|
|
$category = $request->category ?? null;
|
|
if($page){
|
|
$documents = Document::where('page', $page)->orderBy('lft', 'asc');
|
|
if(count($documents->get()) < 1){
|
|
return $this->errorNotFound();
|
|
}
|
|
}else{
|
|
$documents = Document::orderBy('lft', 'asc');
|
|
}
|
|
if($category){
|
|
$documents = $documents->where('document_category_id', $category);
|
|
}
|
|
|
|
return $this->respondWithCollection($documents->get(), new DocumentTransformer($this->locale));
|
|
}
|
|
}
|