PHP code example of mintbridge / eloquent-favourites

1. Go to this page and download the library: Download mintbridge/eloquent-favourites 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/ */

    

mintbridge / eloquent-favourites example snippets


// config/app.php

'providers' => [
    '...',
    'Mintbridge\EloquentFavourites\FavouritesServiceProvider',
];

'aliases' => [
    '...',
    'Favourites' => 'Mintbridge\EloquentFavourites\FavouritesFacade',
];

use Mintbridge\EloquentFavourites\Favouritable;
use Mintbridge\EloquentFavourites\FavouritableInterface;

class Article extends Eloquent implements FavouritableInterface {

    use Favouritable;
    ...
}

$article = Article::find(1);

// add article as a favourite
Favourites::add($article);

// remove article from by a favourite
Favourites::remove($article);

// toggle article as being a favourite
Favourites::toggle($article);

php artisan vendor:publish --provider="Mintbridge\EloquentFavourites\FavouritesServiceProvider" --tag="config"
php artisan vendor:publish --provider="Mintbridge\EloquentFavourites\FavouritesServiceProvider" --tag="migrations"
php artisan migrate
config/eloquent-favourites.php