PHP code example of miladimos / laravel-social

1. Go to this page and download the library: Download miladimos/laravel-social library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

miladimos / laravel-social example snippets


Miladimos\Social\Providers\SocialServiceProvider::class,


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;
}


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
    }
}



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;
}



namespace App\Http\Controllers;

use App\Models\Post;

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

        $post->likes // return all likes


    }
}


php artisan social:install

php artisan migrate