marshmallow / blogs
This packages add the resources you need to create a simple blog in Nova. This is fully extendable.
Requires
- php: ^8.3
- laravel/nova: ^5.0
- marshmallow/breadcrumb: ^v2.0.1
- marshmallow/helpers: ^v2.19.0
- marshmallow/nova-advanced-image: ^v2.2.1
- marshmallow/nova-flexible: ^v5.2.0
- marshmallow/nova-tinymce: ^v2.2.1
- marshmallow/redirectable: ^v5.0.0
- marshmallow/seoable: ^v5.0.2
- marshmallow/sluggable: ^v1.9.0
- marshmallow/translatable: ^v5.0.0
README
Laravel Nova Blogs
This packages add the resources you need to create a simple blog in Nova. This is fully extendable.
Requirements
- PHP
^8.3 - Laravel Nova
^5.0
Installation
Composer
You can install the package via composer:
composer require marshmallow/blogs
Run the install command
The package ships an install command that publishes the config file, runs the
migrations (creating the blogs and blog_tags tables), generates the Blog
and BlogTag Nova resources, and registers the blog detail and tag routes:
php artisan blogs:install
Make sure the routes work
Create a page in your Nova Pages Resource. This page should have the route name blog-detail-page.
Create a page in your Nova Pages Resource. This page should have the route name blog-tag-page.
Configuration
The config file is published to config/blogs.php. Every value can be
overridden to swap in your own models, Nova resources and route names.
| Key | Default | Description |
|---|---|---|
publish_date_format |
d M |
Date format used by Blog::dateFormatted(). |
model.blog |
Marshmallow\Blogs\Models\Blog |
Blog Eloquent model. |
model.blog_tags |
Marshmallow\Blogs\Models\BlogTag |
Blog tag Eloquent model. |
model.user |
App\Models\User |
User model a blog belongs to. |
nova.blog_tags |
Marshmallow\Blogs\Nova\BlogTag |
Nova resource for blog tags. |
nova.user |
App\Nova\User |
Nova resource for the related user. |
images.image |
[1920, 800] |
Dimensions for the main image. |
images.overview_image |
[500, 280] |
Dimensions for the overview image. |
images.detail_image |
[900, 450] |
Dimensions for the detail image. |
routes.blog |
blog-detail |
Route name resolved by Blog::route(). |
routes.blog_tags |
blog-tag |
Route name for a tag overview. |
page_route_names.blog |
blog-detail-page |
Nova page route name for blog details. |
page_route_names.blog_tags |
blog-tag-page |
Nova page route name for tag pages. |
Usage
Blogs are managed through the generated Nova resources. On the frontend you work
with the Marshmallow\Blogs\Models\Blog model, which exposes a number of query
scopes and helper methods:
use Marshmallow\Blogs\Models\Blog; // Published blogs, newest first. $blogs = Blog::published()->ordered()->get(); // Apply the ?q= search filter from the current request. $results = Blog::published()->filtered()->ordered()->get(); // Blogs for a single tag. $tagged = Blog::tagged($tag)->get(); foreach ($blogs as $blog) { $blog->route(); // URL to the blog detail page $blog->dateFormatted(); // publish_date in config('blogs.publish_date_format') $blog->getImage(); // asset URL, defaults to the overview_image column $blog->tag; // related BlogTag $blog->user; // related user }
The Blog model also implements Marshmallow's Seoable and sitemap traits, so
published blogs are automatically included in the generated sitemap.
Changelog
Please see CHANGELOG for more information what has changed recently.
Security
If you discover any security related issues, please email stef@marshmallow.dev instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.