A toolkit package for social networks
composer require miladimos/laravel-social
Miladimos\Social\Providers\SocialServiceProvider::class,
php artisan social:install
php artisan migrate
First add Followable trait to user model
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Miladimos\Social\Traits\Follows\Followable;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use HasFactory,
Followable;
}
and enable to you follow/unfollow feature:
namespace App\Http\Controller;
use App\Models\User;
class YourController extends Controller
{
public function index()
{
$firstUser = User::first();
$secondUser = User::find(2);
$firstUser->follow($secondUser);
$firstUser->unfollow($secondUser);
$firstUser->toggleFollow($secondUser);
$firstUser->followers;
$firstUser->followings;
}
}
How can I help you explore Laravel packages today?