andreaselia / laravel-firefly
A simple forum package for Laravel.
Fund package maintenance!
andreaselia
tomirons
Requires
- php: ^8.0
- illuminate/config: ^8.0|^9.0|^10.0
- illuminate/contracts: ^8.0|^9.0|^10.0
- illuminate/routing: ^8.0|^9.0|^10.0
- illuminate/support: ^8.0|^9.0|^10.0
- spatie/laravel-sluggable: ^3.4.2
Requires (Dev)
- orchestra/testbench: ^8.0
- phpunit/phpunit: ^10.0
README
Laravel Firefly
Firefly is a simple forum package for Laravel, created for ease of use and expansion.
The package ships with a frontend included, but by publishing the packages assets you have the flexibility to customize the available templates and make them match your current applications templates, should you so desire.
Installation
Install the package:
composer require andreaselia/laravel-firefly
Publish package files (config, migrations, assets and views):
php artisan vendor:publish --provider="Firefly\FireflyServiceProvider"
Run the migrations:
php artisan migrate
Add the FireflyUser trait to your User model:
<?php namespace App\Models; use Firefly\Traits\FireflyUser; use Illuminate\Notifications\Notifiable; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use HasFactory, Notifiable, FireflyUser; }
Optional Features
Watchers
You can enable users to "watch" discussions by adding / updating the flag in the config:
'features' => [ 'watchers' => true, // ... ],
This will allow watchers to be notified when new posts are made in the discussion
WYSIWYG Editor
The WYSIWYG Editor uses the Quill library, and the docs can be found here.
You can enable a WYSIWYG editor by adding/updating the flag in the config like so:
'features' => [ // ... 'wysiwyg' => [ 'enabled' => true, 'theme' => 'snow', // More about themes at https://quilljs.com/docs/themes/ 'toolbar_options' => [ // Docs at https://quilljs.com/docs/modules/toolbar/ ['bold', 'italic', 'underline', 'strike'], [['list' => 'ordered'], ['list'=> 'bullet']], ['clean'], ], ], // ... ],
The snow theme and basic editing controls are provided out of the box in the config, but these can be modified to fit your needs.
Correct Posts
You can enable the ability to mark a post as "correct" indicating that it answers the question or is a promoted post. Correct posts are promoted to the top, directly under the initial post.
Note: If you are enabling this on an existing install, you should make sure to run database migrations and then run the posts:set-initial-flag
command, to bring your database up to date. This also introduces two new policies, mark
and unmark
.
'features' => [ 'correct_posts' => true, // ... ],
Reactions
Enabling reactions allows users to react to posts with emojis. This work similarly to Discord, Slack and other popluar messaging systems. Clicking a reaction will add it to the post. Clicking the same one again will remove it.
If you are running an older version or older charset in mySQL or using another database that does not handle native emojis correctly, enabling the convert
flag will convert the emojis to and from html entities so they are stored correctly on the back-end. If you are usingutf8mb4
charsets or newer, this is not needed.
Note: If you are enabling this on an existing install, you should make sure to run database migrations. This also introduces a new policy react
.
'features' => [ 'reactions' => [ 'enabled' => true, 'convert' => true ] // ... ],
Policies
By default, Firefly policies are very permissive. In order to customize the permissions for your own application, please use your AuthServiceProvider
file to overwrite the policies by following the steps below.
- Create your policy files via
php artisan make:policy MyGroupPolicy
- In the generated class, extend the base Firefly policy:
<?php namespace App\Policies; use Illuminate\Auth\Access\HandlesAuthorization; use Firefly\Policies\GroupPolicy; class MyGroupPolicy extends GroupPolicy { // ...
- Implement whatever policy you wish (use the policies in
vendor/andreaselia/laravel-firefly/src/Policies
for reference) - Update the policies array in the
app/Providers/AuthServiceProvider.php
file like so:
<?php use Firefly\Models\Group; // ... protected $policies = [ Group::class => 'App\Policies\MyGroupPolicy', ];
Learn more about Laravel policies here.
Contributing
You're more than welcome to submit a pull request, or if you're not feeling up to it - create an issue so someone else can pick it up.