novius/laravel-filament-news
Filament v4 admin package to manage news posts in Laravel 11+: create posts with categories and tags, attach multiple of each, and browse categories as listing pages. Includes migrations and configurable routes, models, resources, and locales.
Installation:
composer require novius/laravel-filament-news
php artisan migrate
Register Plugin:
Add NewsPlugin::make() to your AdminFilamentPanelProvider:
public function panel(Panel $panel): Panel {
return $panel->plugins([
NewsPlugin::make(),
]);
}
Access Admin Panel:
Navigate to /admin (or your Filament panel URL) and locate the "News" section in the sidebar. You’ll find resources for Posts, Categories, and Tags.
First Use Case: Publish a Post
PostsResource (for managing news articles)CategoryResource (for hierarchical content organization)TagResource (for flexible metadata)config/laravel-filament-news.php to customize route names, models, or locales.php artisan news-manager:publish-front to generate a basic NewsController and routes for public-facing content.// Extend PostResource to add custom fields
use Novius\LaravelFilamentNews\Filament\Resources\Posts\PostResource;
class CustomPostResource extends PostResource {
public static function form(Form $form): Form {
return parent::form($form)
->schema([
// Add a custom field
TextInput::make('custom_field')
->required()
->maxLength(255),
]);
}
}
front_routes_name).#breaking, #tutorial).// In PostResource::table()
->columns([
RelationshipManager::make('categories'),
RelationshipManager::make('tags'),
])
php artisan vendor:publish --tag="lang"
config/laravel-filament-news.php:
'locales' => ['en', 'fr'],
php artisan news-manager:publish-front
NewsController to fetch posts/categories/tags via Eloquent:
use Novius\LaravelFilamentNews\Models\NewsPost;
public function show(NewsPost $post) {
return view('news.post', ['post' => $post]);
}
novius/laravel-meta (included) to dynamically generate SEO tags:
use Novius\LaravelMeta\Facades\Meta;
Meta::setTitle($post->title)
->setDescription($post->excerpt)
->addMeta(['name' => 'keywords', 'content' => $post->tags->pluck('name')]);
php artisan vendor:publish --tag="migrations"
featured_image field to NewsPost:
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Schema::table('news_posts', function (Blueprint $table) {
$table->string('featured_image')->nullable();
});
public function getExcerptAttribute() {
return Str::limit(strip_tags($this->content), 160);
}
config/laravel-filament-news.php:
'resources' => [
'post' => App\Filament\Resources\CustomPostResource::class,
],
use Novius\LaravelFilamentNews\Filament\Widgets\PostsOverview;
public function getWidgets(): array {
return [
PostsOverview::class,
];
}
use Novius\LaravelFilamentNews\Models\NewsPost;
Route::get('/api/posts', function () {
return NewsPost::with(['categories', 'tags'])->get();
});
ResourceController as a base for API routes:
use Filament\Resources\ResourceController;
class PostApiController extends ResourceController {
// Override methods for API-specific logic
}
// In a controller or resource
$posts = NewsPost::with(['categories', 'tags'])->get();
// In PostResource::table()
->paginate(10)
Schema Conflicts:
posts, categories, or tags tables, the package’s migrations will fail. Solution:
config/laravel-filament-news.php:
'models' => [
'post' => App\Models\CustomPost::class,
],
php artisan vendor:publish --tag="migrations"
Filament Version Mismatch:
Missing Frontend Assets:
novius/laravel-nova-translatable for assets. If you skip publishing them:
php artisan vendor:publish --provider="Novius\LaravelNovaTranslatable\LaravelNovaTranslatableServiceProvider" --tag="public"
Localization Gaps:
php artisan vendor:publish --tag="lang"
resources/lang/{locale}/filament-news.php.Route Conflicts:
front_routes_name in the config but forget to clear routes:
php artisan route:clear
Permission Issues:
Gate::define('view-post', function ($user, $post) {
return $user->can('view_any_post');
});
How can I help you explore Laravel packages today?