Skip to content

Commit

Permalink
53. api for info pages
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrakovich committed Jan 26, 2025
1 parent 5b7a40f commit 8308788
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/app/Http/Controllers/Api/InfoPageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Resources\Info\PageResource;
use App\Libraries\Seo\Facades\SeoFacade;
use App\Models\InfoPage;
use App\Services\GoogleTagManagerService;

class InfoPageController extends Controller
{
/**
* Display the specified resource.
*/
public function show(InfoPage $page, GoogleTagManagerService $gtmService): PageResource
{
// $gtmService->setViewForOther();
// SeoFacade::setTitle($currentInfoPage['name']);

return new PageResource($page);
}
}
22 changes: 22 additions & 0 deletions src/app/Http/Resources/Info/PageResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Resources\Info;

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

/**
* @mixin \App\Models\InfoPage
*/
class PageResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return $this->only(['name', 'html']);
}
}
3 changes: 3 additions & 0 deletions src/app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Illuminate\Database\Connection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Application;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Notifications\ChannelManager;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Carbon;
Expand Down Expand Up @@ -78,6 +79,8 @@ public function boot(): void
$app['config']['filesystems.disks.public.url'] = 'https://barocco.by/media';
}

JsonResource::withoutWrapping();

Gate::policy(Role::class, RolePolicy::class);
}

Expand Down
3 changes: 3 additions & 0 deletions src/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use App\Facades\Device;
use App\Http\Controllers\Api\AppController;
use App\Http\Controllers\Api\CatalogController;
use App\Http\Controllers\Api\InfoPageController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Expand All @@ -16,3 +17,5 @@
Route::get('app-init', [AppController::class, 'init']);
Route::get('catalog/{path?}', [CatalogController::class, 'index'])->where('path', '[a-zA-Z0-9/_-]+');
Route::get('product/{product:slug}', [CatalogController::class, 'show'])->withTrashed()->name('product.show');

Route::get('info-page/{page:slug}', [InfoPageController::class, 'show']);

0 comments on commit 8308788

Please sign in to comment.