thefireflytech / filament-blog

Blog plugin for laravel filament
https://packagist.org/packages/firefly/filament-blog
Other
86 stars 34 forks source link

The blog not working with an existing application. #1

Closed jeevatrippy closed 6 months ago

jeevatrippy commented 6 months ago

The blog not working with an existing application.

I'm using filament version 3.2. And running the application in localhost

http://127.0.0.1:8000/blogs ⇒ working fine

http://127.0.0.1:8000/admin/categories ⇒ Not working getting 404 not found error.

Also, I did not get the menus in the sidebar.

My AdminPanelProvider provider

<?php

namespace App\Providers\Filament;

use Filament\Pages;
use Filament\Panel;
use Filament\Widgets;
use Filament\PanelProvider;
use Firefly\FilamentBlog\Blog;
use Filament\Navigation\MenuItem;
use Filament\Support\Colors\Color;
use App\Filament\Pages\EditProfile;
use Filament\Navigation\NavigationGroup;
use Filament\Http\Middleware\Authenticate;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\AuthenticateSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Saade\FilamentFullCalendar\FilamentFullCalendarPlugin;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;

class AdminPanelProvider extends PanelProvider
{

    public function panel(Panel $panel): Panel
    {
        return $panel
            ->default()
            ->databaseNotifications(true)
            ->databaseNotificationsPolling('2s')
            ->id('admin')
            ->path('admin')
            ->login()
            ->font('Poppins')
            ->profile()
            ->userMenuItems([
                'profile' => MenuItem::make()->url(fn (): string => EditProfile::getUrl())
            ])
            ->brandLogo(asset('images/logo.png'))
            ->darkModeBrandLogo(asset('images/logo_white.png'))
            ->favicon(asset('images/fav.png'))
            ->brandLogoHeight('2.5rem')
            ->colors([
                'danger' => Color::Rose,
                'gray' => Color::Gray,
                'info' => Color::Blue,
                'primary' => Color::Indigo,
                'success' => Color::Emerald,
                'warning' => Color::Orange,
            ])
            ->sidebarCollapsibleOnDesktop(true)
            // ->collapsibleNavigationGroups()
            ->navigationGroups([
                NavigationGroup::make('User Managment')
                    ->label('User Managment')
                    ->icon('heroicon-o-users')
                    ->collapsed(true),
                NavigationGroup::make('System Management')
                    ->label('System Management')
                    ->icon('heroicon-o-adjustments-horizontal')
                    ->collapsed(true),
                NavigationGroup::make('All Reports')
                    ->label('All Reports')
                    ->icon('heroicon-o-cursor-arrow-ripple')
                    ->collapsed(true),
                NavigationGroup::make('Utilities')
                    ->label('Utilities')
                    ->icon('heroicon-o-cog')
                    ->collapsed(true),
                NavigationGroup::make('Blog')
                    ->label('Blog')
                    ->icon('heroicon-o-document-minus')
                    ->collapsed(true),

            ])
            ->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
            ->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
            ->pages([
                Pages\Dashboard::class,
            ])
            ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
            ->widgets([
                Widgets\AccountWidget::class,
                // Widgets\FilamentInfoWidget::class,
            ])
            ->plugin(
                FilamentFullCalendarPlugin::make(),
                Blog::make()
            )
            ->middleware([
                EncryptCookies::class,
                AddQueuedCookiesToResponse::class,
                StartSession::class,
                AuthenticateSession::class,
                ShareErrorsFromSession::class,
                VerifyCsrfToken::class,
                SubstituteBindings::class,
                DisableBladeIconComponents::class,
                DispatchServingFilamentEvent::class,
            ])
            ->authMiddleware([
                Authenticate::class,
            ])
            ->viteTheme('resources/css/filament/admin/theme.css');
    }
}

My config file

<?php

use App\Models\User;

/**
 * |--------------------------------------------------------------------------
 * | Set up your blog configuration
 * |--------------------------------------------------------------------------
 * |
 * | The route configuration is for setting up the route prefix and middleware.
 * | The user configuration is for setting up the user model and columns.
 * | The seo configuration is for setting up the default meta tags for the blog.
 * | The recaptcha configuration is for setting up the recaptcha for the blog.
 */

return [
    'route' => [
        'prefix' => 'blogs',
        'middleware' => ['web'],
        // 'home' => [
        //     'name' => 'home',
        //     'url' => env('APP_URL'),
        // ],
        'login' => [
            'name' => 'filamentblog.post.login',
        ],
    ],
    'user' => [
        'model' => User::class,
        'foreign_key' => 'user_id',
        'columns' => [
            'name' => 'name',
            'avatar' => 'avatar',
        ],
    ],
    'seo' => [
        'meta' => [
            'title' => 'Filament Blog',
            'description' => 'This is filament blog seo meta description',
            'keywords' => [],
        ],
    ],

    'recaptcha' => [
        'enabled' => false, // true or false
        'site_key' => env('RECAPTCHA_SITE_KEY'),
        'secret_key' => env('RECAPTCHA_SECRET_KEY'),
    ],
];

My User model

<?php

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;

use Filament\Panel;
use Spatie\Permission\Traits\HasRoles;
use Illuminate\Notifications\Notifiable;
use Filament\Models\Contracts\FilamentUser;
use Firefly\FilamentBlog\Traits\HasBlog;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements FilamentUser
{
    use HasFactory, Notifiable, HasRoles, HasBlog;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'name',
        'email',
        'password',
        'manager_id',
        'senior_manager',
        'regional_manager',
        'sales_head',
        'email_verified_at',
        'remember_token',
        'created_at',
        'updated_at',
        'mobile_number',
        'avatar',
        'is_active',
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'password' => 'hashed',
        ];
    }

    public function canComment(): bool
    {
        // your conditional logic here
        return false;
    }

    public function students()
    {
        return $this->hasMany(Students::class, 'user_id', 'id');
    }

    public function tasks()
    {
        return $this->belongsToMany(Task::class, 'task_user', 'user_id', 'task_id');
    }

    public function canAccessPanel(Panel $panel): bool
    {
        return $this->hasRole(['Admin', 'Accounts', 'BDA', 'Manager', 'Onboard', 'Senior Manager', 'Regional Manager', 'Sales Head', 'CEO', 'Operations Manager','HR','PA','users','Author']) && $this->is_active;
    }
}

Please help me to resolve this issue

sagautam5 commented 6 months ago

It seems following section of your implementation is incorrect.

->plugin(
    FilamentFullCalendarPlugin::make(),
    Blog::make()
)

Since, you are using multiple plugins here, you have to provide it as array.

 ->plugins([
     FilamentFullCalendarPlugin::make(),
     Blog::make()
 ])

I think this should work.

jeevatrippy commented 6 months ago

Thank you !!! 😬😬

AsmitNepali commented 6 months ago

Thank you !!! 😬😬

@jeevatrippy Does it work for you?

jeevatrippy commented 6 months ago

Thank you !!! 😬😬

@jeevatrippy Does it work for you?

Yes... Worked... @AsmitNepali