2017 © Pedro Peláez
 

library favoritable

Laravel Package allows app User to Favorite/Unfavorite Eloquent Model instance

image

mwazovzky/favoritable

Laravel Package allows app User to Favorite/Unfavorite Eloquent Model instance

  • Tuesday, November 28, 2017
  • by mwazovzky
  • Repository
  • 1 Watchers
  • 1 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 6 % Grown

The README.md

Build Status Coverage Status, (*1)

Project: mwazovzky\favoritable

Description

Laravel Package. Allows app User to favorite/unfavorite Eloquent Model instance., (*2)

Version: 0.0.6

Change log:

0.0.6 frontend assets added: <favorite-vidget> vue component
0.0.5 frontend assets added: <favorite> vue component and favorite vidget (blade partial)
0.0.4 routes and controller to favorite/unfavorite model added
0.0.3 package auto discovery (as of Laravel 5.5)
0.0.2 added Model::favoritedBy() methods that define Many-To-Many Polymorphic Relationships
0.0.1 initial project scaffolding
, (*3)

Installation.

  1. Pull the package into Laravel project
composer require mwazovzky/favoritable
  1. For Laravel 5.4 or below register package service provider at /config/app.php.
    Package will be auto-registered for Laravel 5.5 and above.
// file config/app.php

...
'providers' => [
...
\MWazovzky\Favoritable\FavoritableServiceProvider::class
...
];
...
  1. Run database migration to create favorites table
$ php artisan migrate
  1. Use trait Favoritable for every Model that can be favorited by a User.
    Check trait docblocks for a list of available methods.
use \MWazovzky\Favoritable\Favoritable;
  1. Package makes favorite/unfavorite endpoints available for the application via adding corresponding routes to 'web' routes group
Route::post('/favorites/{model}/{id}', 'FavoritesController@store')->name('favorites.store');
Route::delete('/favorites/{model}/{id}', 'FavoritesController@destroy')->name('favorites.destroy');

where model and id are short model class name (kebab-case for KebabCase) and id for the model being favorited/unfavorited.
, (*4)

  1. Run artisan command to publish package assets to /resources/assets/js/components/favoritable/Favorite.vue folder:
$ php artisan vendor:publish --tag=assets
  1. Published vue component are: <favorite> - favorite/unfavorite button <favorite-vidget> toggles favorite query string attribute.
  2. Register components:
// file /resources/assets/js/app.js

Vue.component('favorite', require('./components/favoritable/Favorite.vue'));
Vue.component('favorite-vidget', require('./components/favoritable/FavoriteVidget.vue'));

Component usage, (*5)

<favorite type="modelClass" :model={{ $model->favoriteAttributes() }}></favorite>

where
modelClass is a short model class name (use kebab-case for KebabCase), $model is a model instance,
Model::favoriteAttributes() is a method provided by Favoritable trait.
Any object (e.g. model itself) that has: id, isFavoreted and favoritesCount fields may be passed as component model property., (*6)

<favorite-vidget></favorite-vidget>

Favorite vidget requires no parameters., (*7)

The Versions

28/11 2017

dev-master

9999999-dev

Laravel Package allows app User to Favorite/Unfavorite Eloquent Model instance

  Sources   Download

MIT

by Avatar Mike Wazovzky

laravel

09/11 2017

v0.0.5

0.0.5.0

Laravel Package allows app User to Favorite/Unfavorite Eloquent Model instance

  Sources   Download

MIT

by Avatar Mike Wazovzky

laravel

09/11 2017

v0.0.4

0.0.4.0

Laravel Package allows app User to Favorite/Unfavorite Eloquent Model instance

  Sources   Download

MIT

by Avatar Mike Wazovzky

laravel

22/09 2017

v0.0.3

0.0.3.0

Laravel Package allows app User to Favorite/Unfavorite Eloquent Model instance

  Sources   Download

MIT

by Avatar Mike Wazovzky

laravel

19/05 2017

v0.0.2

0.0.2.0

Demo Package

  Sources   Download

MIT

by Avatar Mike Wazovzky

laravel