skybluesofa / laravel-microblog
This package creates the ability to create micro blog posts for Eloquent Users.
Requires
- php: >=7.1.0
- webpatser/laravel-uuid: 2.*
Requires (Dev)
- codeclimate/php-test-reporter: ^0.3.2
- fzaninotto/faker: ~1.4
- orchestra/testbench: ^4.0
This package is auto-updated.
Last update: 2024-11-17 09:01:02 UTC
README
Laravel 5 Microblog
Create a microblogging platform (e.g., Twitter, Tumblr).
Installation
First, install the package through Composer.
composer require skybluesofa/laravel-microblog
The service provider should be automatically installed on Laravel 5.5+. If you are running a lesser verion, then include the service provider inside config/app.php
.
'providers' => [ ... Skybluesofa\Microblog\ServiceProvider::class, ... ];
Publish config and migrations
php artisan vendor:publish --provider="Skybluesofa\Microblog\ServiceProvider"
Configure the published config in
config\microblog.php
Finally, migrate the database
php artisan migrate
Add Authorship to a User
When a User is a MicroblogAuthor, they can create blog posts.
use Skybluesofa\Microblog\Model\Traits\MicroblogAuthor; class User extends Model { use MicroblogAuthor; ... }
Add Blog Friends to a User
The getBlogFriends() method allows for limiting who can see a User's blog posts.
The Skybluesofa\Microblog\Model\Traits\MicroblogFriends Trait enforces that this method exists on the User model, but does not implement it. You'll need to do that however you see fit. Below is an example:
use Skybluesofa\Microblog\Model\Traits\MicroblogFriends; class User extends Model { use MicroblogFriends; ... public function getBlogFriends() { // Return null to get all users return null; // Return an array to get specific user ids // return [1,2,3]; // Return an empty array to get no user ids (no one else) //return []; } ... }
How to use
Check the Test file to see the package in action
Blog posts
Create a blog post
The savePost() method will create the associated Journal model, if it doesn't exist for the User.
$post = new Post; $post->content = 'This is the story of my life'; $user->savePost($post);
Delete a blog post
$post->delete();
Publish a blog post (move from draft to published status)
$post->publish();
Unpublish a blog post (move from published to draft status)
$post->unpublish();
Make a post visible to friends
$post->share();
or
$post->shareWithFriends();
Make a post visible to everyone who has the URL
$post->shareWithEveryone();
Contributing
See the CONTRIBUTING guide.