Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$config->homeUrl not work correctly #1483

Closed
JeRabix opened this issue Jan 18, 2025 · 7 comments
Closed

$config->homeUrl not work correctly #1483

JeRabix opened this issue Jan 18, 2025 · 7 comments

Comments

@JeRabix
Copy link
Contributor

JeRabix commented Jan 18, 2025

MoonShine Version

3.3.2

Laravel Version

11.38.2

PHP Version

8.4

Database Driver & Version

No response

Description

Когда я логинюсь в админку - да меня кидает на ту страницу что я указал.
Но если я возьму и в строке URL'а введу /admin - то попадаю все равно на dashboard

Steps To Reproduce

Use $config->homeUrl in MoonshineServiceProvider

@JeRabix
Copy link
Contributor Author

JeRabix commented Jan 18, 2025

Ну и к сожалению изначальная проблема не сильно решена. Можно по сути только статичный урл указать. В boot такое ощущение что еще не зарегистрированы еще роуты, даже из web.php роуты получаю ошибку route not exists. С методом toPage - тоже самое

@lee-to
Copy link
Collaborator

lee-to commented Jan 18, 2025

Ну и к сожалению изначальная проблема не сильно решена. Можно по сути только статичный урл указать. В boot такое ощущение что еще не зарегистрированы еще роуты, даже из web.php роуты получаю ошибку route not exists. С методом toPage - тоже самое

а через колбек ? fn() => route() ?

Но если я возьму и в строке URL'а введу /admin - то попадаю все равно на dashboard

А нужен редирект?

@JeRabix
Copy link
Contributor Author

JeRabix commented Jan 18, 2025

Ну и к сожалению изначальная проблема не сильно решена. Можно по сути только статичный урл указать. В boot такое ощущение что еще не зарегистрированы еще роуты, даже из web.php роуты получаю ошибку route not exists. С методом toPage - тоже самое

а через колбек ? fn() => route() ?

Но если я возьму и в строке URL'а введу /admin - то попадаю все равно на dashboard

А нужен редирект?

через колбек действительно работает, но хлебные крошки стают пустыми

Image

по поводу редиректа - ну как по мне если это "home url" - то это страница по умолчанию которая должна открываться всегда на главной, но это не критично, просто у меня этот дашборд пустой всегда

@lee-to
Copy link
Collaborator

lee-to commented Jan 19, 2025

С хлебными странно, а они объявлены на странцие? Какой там урл? В шаблоне присутствуют?

@JeRabix
Copy link
Contributor Author

JeRabix commented Jan 20, 2025

Это просто дефолтно сгенерированный ресурс, если убрать вызов homeUrl() все работает

@JeRabix
Copy link
Contributor Author

JeRabix commented Jan 20, 2025

Resource

<?php

declare(strict_types=1);

namespace App\MoonShine\Resources\ParsingMessage;

use MoonShine\UI\Fields\ID;
use MoonShine\UI\Fields\Url;
use MoonShine\UI\Fields\Text;
use MoonShine\Support\ListOf;
use MoonShine\UI\Fields\Enum;
use MoonShine\UI\Fields\Number;
use MoonShine\Laravel\Enums\Action;
use MoonShine\Contracts\UI\FieldContract;
use App\Models\ParsingMessage\ParsingMessage;
use MoonShine\Contracts\UI\ComponentContract;
use MoonShine\Laravel\Resources\ModelResource;
use App\Services\ParsingMessage\Enum\MessageStatus;

/**
 * @extends ModelResource<ParsingMessage>
 */
class ParsingMessageResource extends ModelResource
{
    protected string $model = ParsingMessage::class;

    protected string $title = 'Сообщения';

    protected function search(): array
    {
        return [
            'id',
            'external_id',
            'external_chat_id',
            'external_sender_id',
            'external_sender_username',
            'message',
            'message_link',
        ];
    }

   protected function activeActions(): ListOf
   {
       return parent::activeActions()->except(Action::CREATE);
   }

    /**
     * @return list<FieldContract>
     */
    protected function indexFields(): iterable
    {
        return [
            ID::make()
                ->sortable(),

            Text::make('message')
                ->sortable()
                ->disabled()
                ->canApply(fn() => false),

            Enum::make('status')
                ->attach(MessageStatus::class)
                ->sortable(),

            Url::make('message_link')
                ->blank()
                ->disabled()
                ->canApply(fn() => false),

            Number::make('external_id')
                ->sortable()
                ->disabled()
                ->canApply(fn() => false),

            Number::make('external_chat_id')
                ->sortable()
                ->disabled()
                ->canApply(fn() => false),

            Number::make('external_sender_id')
                ->sortable()
                ->disabled()
                ->canApply(fn() => false),

            Text::make('external_sender_username')
                ->sortable()
                ->disabled()
                ->canApply(fn() => false),
        ];
    }

    /**
     * @return list<ComponentContract|FieldContract>
     */
    protected function formFields(): iterable
    {
        return $this->indexFields();
    }

    /**
     * @return list<FieldContract>
     */
    protected function detailFields(): iterable
    {
        return $this->indexFields();
    }

    /**
     * @param ParsingMessage $item
     *
     * @return array<string, string[]|string>
     * @see https://laravel.com/docs/validation#available-validation-rules
     */
    protected function rules(mixed $item): array
    {
        return [];
    }

    protected function filters(): iterable
    {
        return [
            Enum::make('status')
                ->attach(MessageStatus::class)
                ->nullable(),
        ];
    }
}

Service provider:

<?php

declare(strict_types=1);

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use MoonShine\Laravel\Pages\Crud\IndexPage;
use MoonShine\Laravel\DependencyInjection\MoonShine;
use App\MoonShine\Pages\TgAccount\TgAccountFormPage;
use App\MoonShine\Resources\TgAccount\TgAccountResource;
use MoonShine\Contracts\Core\DependencyInjection\CoreContract;
use MoonShine\Laravel\DependencyInjection\MoonShineConfigurator;
use App\MoonShine\Resources\ParsingMessage\ParsingMessageResource;
use MoonShine\Contracts\Core\DependencyInjection\ConfiguratorContract;

class MoonShineServiceProvider extends ServiceProvider
{
    /**
     * @param MoonShine $core
     * @param MoonShineConfigurator $config
     *
     */
    public function boot(CoreContract $core, ConfiguratorContract $config): void
    {
        // работает корректно
        $config->homeUrl('/admin/resource/parsing-message-resource/index-page');

        // вот это уже вызывает пустоту в бреадкрамс, но тоже работает
        $config->homeUrl(fn() => toPage(
            page: IndexPage::class,
            resource: ParsingMessageResource::class,
        ));

        $core
            ->resources([
                ParsingMessageResource::class,
                TgAccountResource::class,
            ])
            ->pages([
                ...$config->getPages(),
                TgAccountFormPage::class,
            ]);
    }
}

@lee-to
Copy link
Collaborator

lee-to commented Jan 20, 2025

protected function onLoad(): void
{
    parent::onLoad();

    $this->getIndexPage()->breadcrumbs([
        '#' => 'Comments'
    ]);
}

And update to 3.3.5 and add response

class Dashboard extends Page
{
    protected function modifyResponse(): ?Response
    {
        return redirect('/test');
    }
}

@lee-to lee-to closed this as completed Jan 20, 2025
lee-to added a commit that referenced this issue Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants