fuelviews/laravel-sabhero-blog

v0.0.1 2025-03-04 18:11 UTC

This package is auto-updated.

Last update: 2025-03-07 15:27:14 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

If your project is not already using Filament, you can install it by running the following commands:

composer require filament/filament:"^3.2" -W
php artisan filament:install --panels

Install the SabHero Blog Plugin by running the following command:

composer require fuelviews/sabhero-blog -W

Usage

After composer require, you can start using the SabHero Blog Plugin by running the following command:

php artisan sabhero-blog:install

This command will publish sabhero-blog.php config file and migration files.

<?php

use App\Models\User;

return [
    'tables' => [
        'prefix' => 'blog_',
    ],
    'route' => [
        'prefix' => 'blog',
        'middleware' => ['web'],
    ],
    'user' => [
        'model' => User::class,
        'foreign_key' => 'user_id',
        'columns' => [
            'name' => 'name',
            'slug' => 'slug',
        ],
    ],
    'heading_permalink' => [
        'html_class' => 'scroll-mt-40',
    ],
    'dropdown' => [
        'name' => 'Posts',
    ],
    'crm' => [
        'name' => 'CRM',
        'link' => '#',
    ],
];

Before running the migration, you can modify the sabhero-blog.php config file to suit your needs.

You can publish the config file with:

php artisan vendor:publish --tag="sabhero-blog-config"

Optionally, you can publish the views using

php artisan vendor:publish --tag="sabhero-blog-views"

Migrate the database

After modifying the sabhero-blog.php config file, you can run the migration by running the following command:

php artisan migrate

Attach SabHero Blog panel to the dashboard

You can attach the SabHero Blog panel to the dashboard by adding the following code to your panel provider: Add SabHeroBlog::make() to your panel passing the class to your plugins() method.

use Fuelviews\SabHeroBlog\SabHeroBlog;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            SabHeroBlog::make()
        ])
}

Authorizing access to the panel

By default, all App\Models\Users can access Filament locally. To allow them to access Filament in production, you must take a few extra steps to ensure that only the correct users have access to the app.

<?php

namespace App\Models;

use Filament\Panel;
use Fuelviews\SabHeroBlog\Traits\HasAuthor;
use Fuelviews\SabHeroBlog\Traits\HasBlog;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Filament\Models\Contracts\FilamentUser;
use Filament\Models\Contracts\HasAvatar;

class User extends Authenticatable implements FilamentUser, HasAvatar
{
    use HasFactory, Notifiable, HasBlog, HasAuthor;
    
    public function canAccessPanel(Panel $panel): bool
    {
        return str_ends_with($this->email, '@your-domain-here.com');
    }
}

You can publish and run the migrations with:

php artisan vendor:publish --tag="sabhero-blog-migrations"
php artisan migrate

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.