Download the PHP package mnaimjons/laravel-stories without Composer
On this page you can find all versions of the php package mnaimjons/laravel-stories. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mnaimjons/laravel-stories
More information about mnaimjons/laravel-stories
Files in mnaimjons/laravel-stories
Package laravel-stories
Short Description A Laravel package to add stories functionality to any model.
License MIT
Informations about the package laravel-stories
Laravel Stories Package
The Laravel Stories Package provides "stories" functionality for any model in your Laravel application, similar to how it's implemented in social media platforms. The package supports:
- Media uploads (images and videos) using Spatie Media Library.
- Comments on stories.
- Reactions to stories.
- Tracking views of stories.
- Automatic deletion of expired stories.
Note: In the current version, all stories are visible to all users. Future releases will include privacy settings.
Table of Contents
- Installation
- Configuration
- Usage
- Adding the Trait to Your Model
- Creating Stories
- Viewing Stories
- Adding Comments
- Adding Reactions
- Tracking Views
- API Routes
- Scheduling Tasks
- Customization
- Testing
- License
- Contact
Installation
-
Install the package via Composer:
-
Publish and run the migrations:
-
Publish the configuration:
- Install Spatie Media Library (if not already installed):
Configuration
The configuration file config/stories.php contains the package settings:
You can change the default story expiration time by modifying the default_expiration value.
Usage
Adding the Trait to Your Model
Add the HasStoriesTrait trait and implement the HasStories interface in the model you want to associate stories with (e.g., the User model):
Creating Stories
You can create stories for any model that uses the HasStoriesTrait. Here's an example of creating a story for the currently authenticated user:
Note: Ensure your form includes a file input field named media and has the multipart/form-data encoding type.
Viewing Stories
Retrieve active stories for a user:
Adding Comments
Users can leave comments on stories:
Or through a controller:
Adding Reactions
Users can react to stories (e.g., send emojis):
If a user has already reacted to this story, their reaction will be updated.
Tracking Views
Each time a user views a story, you can record the view:
Or automatically when displaying stories via a controller:
API Routes
The package provides a set of API routes for working with stories. The routes are defined in routes/api.php and are automatically loaded by the service provider.
List of Routes
| Method | Route | Action |
|---|---|---|
| POST | /stories |
Create a new story |
| GET | /stories |
Get a list of active stories |
| GET | /stories/{id} |
View a specific story |
| POST | /stories/{id}/comment |
Add a comment to a story |
| POST | /stories/{id}/react |
Add or update a reaction to a story |
API Usage Examples
Creating a Story
Getting Active Stories
Adding a Comment
Adding a Reaction
Scheduling Tasks
To automatically delete expired stories and associated media files, add the cleanup command to your task scheduler in app/Console/Kernel.php:
The stories:cleanup command deletes all stories that have expired and cleans up associated media collections.
Customization
Adjusting Story Expiration Time
You can change the default story expiration time by modifying the default_expiration value in config/stories.php:
Extending Models
If you need to extend the functionality of the package's models (e.g., Story, StoryComment, StoryReaction), you can create your own models and configure the package to use them.
Adding Privacy Settings
In the current version, all stories are visible to all users. You can extend the package by adding privacy settings to the Story model and updating access policies.
Testing
It is recommended to cover your code with tests to ensure the package works correctly in your application.
Example Test
License
The package is open-sourced software licensed under the MIT license.
Contact
- Author: Mnaimjons
- Email: [email protected]
- GitHub: github.com/mnaimjons
Thank You
- Spatie for their excellent Laravel Media Library package.
- Laravel Community for their contributions to the framework.
Feedback
If you have any questions or suggestions, please create an issue on GitHub or submit a Pull Request.
Conclusion
The Laravel Stories Package provides a powerful and flexible way to add stories functionality to your application. It integrates easily with existing models and allows users to interact through stories, comments, and reactions.
Start using it today to enhance user engagement in your application!
Key Features
- Easy Integration: Easily attach to any model in your application.
- Flexible Configuration: Customize story lifetime and extend functionality.
- Media Support: Uses Spatie Media Library for handling images and videos.
- User Interaction: Supports comments and reactions on stories.
- Automatic Maintenance: Provides a command to clean up expired stories.
Requirements
- PHP: >=7.4
- Laravel: ^8.0|^9.0|^10.0
- Spatie Media Library: ^10.0
Development Installation
-
Clone the repository:
-
Install dependencies:
-
Link the package in your application:
In your application's
composer.json, add:Then require the package:
Contribution
We welcome contributions from the community! If you'd like to contribute to the development of the package, please:
- Fork the repository.
- Create a new branch for your feature (
git checkout -b feature/my-feature). - Make your changes and commit them (
git commit -am 'Add new feature'). - Push your changes to the repository (
git push origin feature/my-feature). - Create a Pull Request.
Thank you for using the Laravel Stories Package!
All versions of laravel-stories with dependencies
illuminate/support Version ^8.0|^9.0|^10.0
spatie/laravel-medialibrary Version ^10.0