Create a microblogging platform (e.g., Twitter, Tumblr).
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
When a User is a MicroblogAuthor, they can create blog posts.
use Skybluesofa\Microblog\Model\Traits\MicroblogAuthor;
class User extends Model
{
use MicroblogAuthor;
...
}
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 [];
}
...
}
Check the Test file to see the package in action
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);
$post->delete();
$post->publish();
$post->unpublish();
$post->share();
or
$post->shareWithFriends();
$post->shareWithEveryone();
See the CONTRIBUTING guide.