Code Monkey home page Code Monkey logo

laravel-social's Introduction

Starts Forks

Laravel social package

A toolkit package for social networks

Installation

  1. Run the command below to add this package:
composer require miladimos/laravel-social
  1. Open your config/socials.php and add the following to the providers array:
Miladimos\Social\Providers\SocialServiceProvider::class,
  1. Run the command below to install package:
php artisan social:install
  1. Run the command below to migrate database:
php artisan migrate

Features

Tag:

First add Taggable trait to models that you want have tags

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Miladimos\Social\Traits\Taggable;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasFactory,
        Taggable;
}

Second you can work with tags:

namespace App\Http\Controller;

use App\Models\Post;
use Miladimos\Social\Models\Tag;

class YourController extends Controller
{
    public function index()
    {   
        // first you can create custom tags
        $tag = Tag::create(['name' => 'tag']);   

        $post = Post::first();

        $post->tags; // return attached tags

        $post->attach($tag); // attach one tag

        $post->detach($tag); // detach one tag

        $post->syncTags([$tags]); // sync tags

        $tag->taggables; // return morph relation to tagged model
    }
}

tag model have soft deletes trait.

Like

Bookmark

Follow

Category

First add Taggable trait to models that you want have attachments

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Miladimos\Social\Traits\Taggable;

class Post extends Model
{
    use HasFactory,
        Taggable;
}

Methods

in controllers you have these methods:

namespace App\Http\Controllers;

use App\Models\Post;

class PostController extends Controller
{
    public function index()
    {
        $post = Post::find(1);

        $post->likes // return all likes


    }
}

Features

Like

Favorite

Bookmark

Follow \ Unfollow

Comment

$post = Post::find(1);

$post->comment('This is a comment');

$post->commentAsUser($user, 'This is a comment from someone else'); $comment = $post->comments->first();

$comment->approve();

Auto Approve Comments implements Commentator needsCommentApproval false

// Retrieve all comments $comments = $post->comments;

// Retrieve only approved comments $approved = $post->comments()->approved()->get();

Vote / Rate System

laravel-social's People

Contributors

miladimos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

militest zaghadon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.