PHP code example of laravel-interaction / favorite
1. Go to this page and download the library: Download laravel-interaction/favorite 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/ */
laravel-interaction / favorite example snippets
use Illuminate\Database\Eloquent\Model;
use LaravelInteraction\Favorite\Concerns\Favoriter;
class User extends Model
{
use Favoriter;
}
use Illuminate\Database\Eloquent\Model;
use LaravelInteraction\Favorite\Concerns\Favoriteable;
class Channel extends Model
{
use Favoriteable;
}
use LaravelInteraction\Favorite\Tests\Models\Channel;
/** @var \LaravelInteraction\Favorite\Tests\Models\User $user */
/** @var \LaravelInteraction\Favorite\Tests\Models\Channel $channel */
// Favorite to Favoriteable
$user->favorite($channel);
$user->unfavorite($channel);
$user->toggleFavorite($channel);
// Compare Favoriteable
$user->hasFavorited($channel);
$user->hasNotFavorited($channel);
// Get favorited info
$user->favoriterFavorites()->count();
// with type
$user->favoriterFavorites()->withType(Channel::class)->count();
// get favorited channels
Channel::query()->whereFavoritedBy($user)->get();
// get favorited channels doesnt favorited
Channel::query()->whereNotFavoritedBy($user)->get();