Download the PHP package unrulynatives/attitudes without Composer
On this page you can find all versions of the php package unrulynatives/attitudes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download unrulynatives/attitudes
More information about unrulynatives/attitudes
Files in unrulynatives/attitudes
Package attitudes
Short Description Laravel 5 Upvote/Downvote system
License MIT
Homepage https://development.unrulynatives.com
Informations about the package attitudes
What it is
This is a complete upvote and downvote solution for Laravel >= 5.3.
- Allows upvoting & downvoting, binary or multiple steps.
- Records memos (comments) by the voting user in the same table.
- Out-of-the-box migration tool for data from
rtconner/laravel-likeable
package. - Allows assigning objects to favorite categories (only one per voted object though).
Contributors welcome. Any feature suggestions? Submit an issue.
Current version:
List of all features
This package delivers several solutions working in the same DB table. Pick one or use all to get functionality you need. Three values available for storing likes and upvotes are up to you: binary, negative value or null
.
-
importance
- might be used for observing and prioritizing content with values from range0
to10
, or just any, including negative. -
attitude
- might store values-1
,0
,1
for dislikes and likes (upvotes and downvotes). As above, the scope of the values can be decided by developer, e.-2
for hate and-3
for going Berserk over the object is possible. -
activated
- just to give an example the field might store values-1
,0
,1
. Useful for for content filtering features. -
favoritetype_id
- Just a scaffold for future development. An item might be stored in favorites under a certain subcategory.null
would mean the root folder. This feature would require an extra modelFavoritetype
. user_notes
- allows user to take notes concerning a model (still to do). I suggest a maximum number of characters at 150, so that the table won't be heavy.
To do
- functions for votes counters
- example views for various cases of voting counters
- example for adding user notes
- splitting the collection used for migrating from rtconner - now it submits to php timeout limits
Conntributing
While the package does the job perfectly now, please give me some time to make the code look more professional. Contributors welcome!
Installation
- Add this line to your 'composer.json`
"unrulynatives/attitudes": "^1.0"
-
register the service provider in
config/app.php
.Unrulynatives\Attitudes\AttitudesServiceProvider::class,
- In your
User.php
model register this trait.
The trait will make these two functions available. (As an alternative, you can implement them directly in the model file.)
- Register trait in your models
To all models you want to enable the voting ystem, register this trait:
The trait will make the below three functions available. (As an alternative, you can implement them directly in the model file.)
- Publish assets Publish migrations, views, controller and other assets from this package into your Laravel app:
php artisan vendor:publish --provider="Unrulynatives\Attitudes\AttitudesServiceProvider" --force
- Run migrations
Now run the migrations with command
php artisan migrate
. Verify that the tableuserattitudes
was created.
Note: make sure to make your adjustments on copies, as newer version of this package might overwrite your changes (note the --force
option in the publish command.)
- (optional) Setup the demo feature
While the DB in demonstration page will be seeded by controller function, you can also seed the DB here.
in your \database\seeds\DatabaseSeeder.php
run()
function declare this seed file:
\database\seeds\UnAQuotationsTableSeeder.php
and run php artisan db:seed
.
Route::any('{itemkind}/{id}/set_user_attitude', ['as' => 'attitudes.set_user_attitude', 'uses' => 'AttitudesController@set_user_attitude']); Route::any('{itemkind}/{id}/set_user_importance', ['as' => 'attitudes.set_user_importance', 'uses' => 'AttitudesController@set_user_importance']);
// features is a name of your model
@include('userattitudes._userattitudes_attitude_toggle_abstracted', ['itemkind' => $itemkind,'o' => $o, 'attitude' => (($cua = $o->user_approach(Auth::user())) ? $cua->attitude : NULL)])
@include('userattitudes._userattitudes_importance_toggle_abstracted', ['itemkind' => $itemkind,'o' => $o, 'importance' => (($cua = $o->user_approach(Auth::user())) ? $cua->importance : NULL)])
use Illuminate\Database\Eloquent\Relations\Relation;
// ...
public function boot()
{
Relation::morphMap([
'user' => User::class,
'quotation' => \App\Models\UnAQuotation::class,
]);
}
12. Define a csrf token
Be sure that the head of your page contains the below declaration, otherwise you will meet with unexpected behavior of the script:
`<meta name="csrf-token" content="{{ csrf_token() }}" />`
### That's it! Now user choices should be stored in the database table `userattitudes`.
## Working demo.
If you installed this package correctly, point your browser to `attitudes-demo`.
- You should be logged in
- you sould have the `app\Models\Feature` model defined and at least one record in your database present. You can just simply use your own model for your test run - it's up to you.
An online demo is available at http://dev.unrulynatives.com/attitudes-demo
## Data migration from other packages
Added feature to migrate data from rtconner's package. See url `attitudes-migrate-likeable`
## Usage & Examples
### Count total votes of an object
`$this->countallvotes` - prints total number of votes cast by all users
`$this->countdownvotes`- prints total number of DOWN-votes cast by all users
`$this->countupvotes`- prints total number of UP-votes cast by all users
### collections
- `Quotation::whereUpvotedBy(Auth::id())->get();` // collection of Quotations upvoted by the user
- `Quotation::whereDownvotedBy(Auth::id())->get();` // collection of Quotations downvoted by the user
- `Quotation::whereVotedBy(Auth::id())->get();` // collection of Quotations voted in any way by the user (mind that the function counts records existing in DB, so it includes `null` and `0`)
### backend
IMPORTANT NOTE: In this package the assumed convention for model names is singular with capitalized first letter.
Mind the variable `itemkind`. It MUST be plural form of your model name.
If you have another system, you must rework the backend solutions of this package.
### Frontend
After publishing the views, in your app's `resources/views/` folder you will find a folder `userattitudes`. Inside you will find several files. In files included by the below templates you can define classes for your voting buttons and model affected by them.
To have everything work well, start with including
`@include('userattitudes.set_attitudes_2')`
(works with Bootstrap 4 and font Awesome (for thumbs up & down icons))
Other frontend solutions
`@include('userattitudes.set_attitudes_1')` will work nice with
(works well with the UnrulyNatives Starter Kit package - need extra icon fonts installed)
## Help and documentation
point your browser to `attitudes-docs` to see instructions. If you cannot see the docs, then you have a problem to solve. Good luck!
After you use the `publish` command, the file will be located at `resources/views/userattitudes/features/index.blade.php`