This is a simple, bare-bones blog package for Laravel. The main advantage is that it is easy to install and it supports localization, with English and French language support out of the box. This package is what I use for my blog on this site and on other sites.
This package uses Laravel's Auth so you need to have that installed before installing this. You can install that with:
php artisan make:auth
Then install with composer:
composer require escuccim/larablog
Then register the components in /config/app.php:
Add the following to the 'providers' array:
Escuccim\LaraBlog\blogServiceProvider::class,
Laracasts\Flash\FlashServiceProvider::class,
Roumen\Feed\FeedServiceProvider::class,
And add the following to 'aliases' array:
'Form' => Collective\Html\FormFacade::class,
'Feed' => Roumen\Feed\Feed::class,
Run the database migrations to create the blog tables and update the users table:
php artisan migrate
To enable the JavaScript features of the administrative pages you need to add the following to the head of your layouts/app.blade.php view:
<script src="/js/app.js"></script>
@stack('scripts')
Note that the script tag needs to be moved from the bottom of the layout to the header.
By default I use my own middleware to determine if the user had administrator privileges. If you wish to use your own middleware or stick with Laravel's Auth middleware you can do so by updating the config (see below).
This package contains its own routes, models, controllers and views so should work after installation. To access it just go to /blog. This package also includes an RSS feed which is generated using roumen/feed and which is available at /feed.
If you wish to edit my views or other files you can publish them to your application:
php artisan vendor:publish
This will publish all of the files. To only publish certain files add --tag=[group]
, using the groups listed below:
To add additional languages, publish the lang files and then create new directories under /resources/lang/vendor/larablog corresponding to the language you wish to add. Copy the blog.php file into your new directory and put the translations into the new language into the array.
Note that out of the box the blog will use the languages specified in config/app.php under 'locale'. If you wish to have the blog translate on a per request basis you will need to provide the code for this, or use my package escuccim/translate.
If the use_rich_card value in the config is set to true a structured data script will be included in the display of the article. If this is set to true then a field will be shown when adding or editing an article to allow you to specify an URI for an image which will be included in the rich card. The rich card will also look for a logo in /public/images/logo.png which will be displayed if it exists.
To access the configuration files you need to publish the config file to /config/blog.php with:
php artisan vendor:publish --tag=config
.
The config file has the following values:
Note that in order to leave a comment the user must be logged in, so I would not recommend using 'auth' as the middleware as this will allow any registered user to add, edit and delete articles. Also note that the code for displaying comments will reference a field in the user table called 'image' to display an avatar for the user if there is data in the field. If you wish to allow users to set avatars you will need to write the code for this yourself.