Skip to content

Commit

Permalink
Tiding up
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdordoy committed Oct 16, 2024
1 parent 1596818 commit e05322c
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
{
public function up()
{
Schema::create(Document::TABLE_NAME->value, function (Blueprint $table) {
$table->id();
$table->morphs('model');
$table->string('name')->unique();
$table->text('doctype')->nullable();
$table->timestamps();
});
Schema::create(Document::TABLE_NAME->value, fn (Blueprint $table) => Document::toTable($table));
}
};
2 changes: 0 additions & 2 deletions src/Actions/RegisterRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ class RegisterRoutes
public function __invoke()
{
Route::resource('/htmlable/documents', DocumentsController::class);

Route::get('/htmlable/documents/{document}/render', RenderDocumentController::class);
Route::get('/htmlable/documents/{document}/download', DownloadDocumentController::class);

Route::resource('/htmlable/elements', ElementsController::class);

Route::get('/htmlable/elements/{element}/render', RenderElementController::class);

Route::resource('/htmlable/values', ValuesController::class);
Expand Down
13 changes: 13 additions & 0 deletions src/Enums/Tables/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@

namespace JamesDordoy\HTMLable\Enums\Tables;

use Illuminate\Database\Schema\Blueprint;

enum Document: string
{
case TABLE_NAME = 'documents';

public static function toTable(Blueprint $table): callable
{
return function() use ($table) {
$table->id();
$table->morphs('model');
$table->string('name')->unique();
$table->text('doctype')->nullable();
$table->timestamps();
};
}
}
8 changes: 8 additions & 0 deletions src/Enums/Tables/Element.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace JamesDordoy\HTMLable\Enums\Tables;

enum Element: string
{
case TABLE_NAME = 'elements';
}
8 changes: 8 additions & 0 deletions src/Enums/Tables/Value.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace JamesDordoy\HTMLable\Enums\Tables;

enum ElemeValuet: string
{
case TABLE_NAME = 'values';
}
3 changes: 2 additions & 1 deletion src/Http/Controllers/Documents/DocumentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
use Illuminate\Http\Request;
use JamesDordoy\HTMLable\Http\Requests\Documents\CreateDocumentRequest;
use JamesDordoy\HTMLable\Http\Resources\Documents\DocumentResource;
use JamesDordoy\HTMLable\Http\Resources\Documents\DocumentsResource;
use JamesDordoy\HTMLable\Models\Document;

class DocumentsController
{
public function index(Request $request)
{
return Document::get();
return new DocumentsResource(Document::get());
}

public function create(Request $request)
Expand Down
4 changes: 3 additions & 1 deletion src/Http/Resources/Documents/DocumentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class DocumentResource extends JsonResource
{
public function toArray(Request $request): array
{
return parent::toArray($request);
return [
...parent::toArray($request),
];
}
}
16 changes: 16 additions & 0 deletions src/Http/Resources/Documents/DocumentsResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace JamesDordoy\HTMLable\Http\Resources\Documents;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;

class DocumentsResource extends ResourceCollection
{
public function toArray(Request $request): array
{
return [
'data' => $this->collection,
];
}
}

0 comments on commit e05322c

Please sign in to comment.