skybluesofa/laravel-microblog

This package creates the ability to create micro blog posts for Eloquent Users.

0.5.0 2020-02-17 21:08 UTC

This package is auto-updated.

Last update: 2024-11-17 09:01:02 UTC


README

Build Status Code Climate Test Coverage Total Downloads Version Software License

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.