Skip to content

Commit

Permalink
Page fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelson Alexandre Mutane committed Jul 14, 2023
1 parent 6e0b082 commit 53c9192
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 10 deletions.
15 changes: 12 additions & 3 deletions app/Actions/Page/GetPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@

use App\Models\Page;
use Inertia\Inertia;
use Lorisleiva\Actions\Concerns\AsAction;
use Lorisleiva\Actions\Concerns\AsController;

class GetPage
{
use AsController;
use AsAction;


public function handle() :Page {

return Page::first() ?? Page::create([]);
}




public function asController()
{
$page = Page::first() ?? Page::create([]);

return Inertia::render('Page/Index', [
'pageData' => $page->getData(),
'pageData' => $this->handle()->getData(),
]);
}
}
3 changes: 2 additions & 1 deletion app/Actions/Website/About.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Actions\Website;

use App\Actions\Page\GetPage;
use App\Models\Page;
use App\Support\Enums\Pages;
use Lorisleiva\Actions\Concerns\AsController;
Expand All @@ -13,7 +14,7 @@ class About
public function asController()
{
return view('website.about', [
'page' => Page::with('media')
'page' => GetPage::run()->with('media')
->first()?->getFirstMedia(Pages::ABOUT),
]);
}
Expand Down
3 changes: 2 additions & 1 deletion app/Actions/Website/GetPolicies.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Actions\Website;

use App\Actions\Page\GetPage;
use App\Models\Page;
use App\Models\Politica;
use App\Support\Enums\Pages;
Expand All @@ -15,7 +16,7 @@ public function asController()
{
return view('website.policy', [
'policy' => Politica::first(),
'page' => Page::with('media')->first()?->getFirstMedia(Pages::POLICY),
'page' => GetPage::run()->with('media')->first()?->getFirstMedia(Pages::POLICY),
]);
}
}
3 changes: 2 additions & 1 deletion app/Actions/Website/GetTerms.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Actions\Website;

use App\Actions\Page\GetPage;
use App\Models\Page;
use App\Models\Termo;
use App\Support\Enums\Pages;
Expand All @@ -15,7 +16,7 @@ public function asController()
{
return view('website.terms', [
'terms' => Termo::first(),
'page' => Page::with('media')->first()?->getFirstMedia(Pages::TERMS),
'page' => GetPage::run()->with('media')->first()?->getFirstMedia(Pages::TERMS),
]);
}
}
5 changes: 3 additions & 2 deletions app/Actions/Website/Welcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Actions\Website;

use App\Actions\Page\GetPage;
use App\Models\Banner;
use App\Models\Imovel;
use App\Models\Page;
Expand All @@ -16,8 +17,8 @@ public function asController()
{
//
return view('website.welcome', [
'page' => Page::with('media')->first()?->getFirstMedia(Pages::HOME),
'thumb' => Page::with('media')->first()?->getFirstMedia(Pages::HOME)->responsiveImages()->getPlaceholderSvg(),
'page' => GetPage::run()->with('media')->first()?->getFirstMedia(Pages::HOME),
'thumb' => GetPage::run()->with('media')->first()?->getFirstMedia(Pages::HOME)->responsiveImages()->getPlaceholderSvg(),
'relevantImovels' => $this->getRelevantImovels(),
'lastestImovels' => Imovel::with(['bairro.cidade', 'intermediationRule', 'imovelFor', 'tipo_de_imovel', 'status', 'comentarios', 'ratings'])->latest('created_at')->get()->take(6),
'banners' => Banner::with('media')->first(),
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Actions\Imovel\ImovelTrashCount;
use App\Actions\Message\MessageCount;
use App\Actions\Page\GetPage;
use App\Data\RoleData;
use App\Models\Page;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -35,6 +36,7 @@ public function version(Request $request): string|null
*/
public function share(Request $request): array
{

return array_merge(parent::share($request), [
'auth' => [
'user' => $request->user()?->load('roles')->getData(),
Expand All @@ -43,7 +45,7 @@ public function share(Request $request): array
'roles' => RoleData::collection(Role::all()),
'mails' => MessageCount::run(),
'trash' => ImovelTrashCount::run($request->user()),
'globals' => Page::first()->getData(),
'globals' => GetPage::run()->getData(),
'site' => config('app.url'),
'ziggy' => function () use ($request) {
return array_merge((new Ziggy)->toArray(), [
Expand Down
3 changes: 2 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Providers;

use App\Actions\Page\GetPage;
use App\Models\Page;
use App\Models\TipoDeImovel;
use Illuminate\Database\Eloquent\Builder;
Expand Down Expand Up @@ -33,7 +34,7 @@ public function boot()
{
Paginator::useBootstrapFive();
view()->share([
'globals' => Page::first()?->getData(),
'globals' => GetPage::run()?->getData(),
'imovelTypes' => TipoDeImovel::all(),
]);

Expand Down

0 comments on commit 53c9192

Please sign in to comment.