Download the PHP package mwazovzky/favoritable without Composer
On this page you can find all versions of the php package mwazovzky/favoritable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package favoritable
Project: mwazovzky\favoritable
Description
Laravel Package. Allows app User to favorite/unfavorite Eloquent Model instance.
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
Installation.
-
Pull the package into Laravel project
-
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. -
Run database migration to create
favorites
table -
Use trait Favoritable for every Model that can be favorited by a User.
Check trait docblocks for a list of available methods. - Package makes
favorite
/unfavorite
endpoints available for the application via adding corresponding routes to 'web' routes group
where model
and id
are short model class name (kebab-case
for KebabCase
) and
id for the model being favorited/unfavorited.
-
Run artisan command to publish package assets to
/resources/assets/js/components/favoritable/Favorite.vue
folder: - Published vue component are:
<favorite>
- favorite/unfavorite button<favorite-vidget>
togglesfavorite
query string attribute. - Register components:
Component usage
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.
Favorite vidget requires no parameters.