Download the PHP package avxman/ratings without Composer
On this page you can find all versions of the php package avxman/ratings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download avxman/ratings
More information about avxman/ratings
Files in avxman/ratings
Package ratings
Short Description The module ratings post, comment or other object for laravel >=8.0
License MIT
Homepage https://github.com/avxman/ratings
Informations about the package ratings
Модуль рейтинга laravel >= 8.0
Работа с рейтингом на сайте. Вывод и сохранение рейтинга.
Установка модуля с помощью composer
Настройка модуля
После установки модуля не забываем объязательно запустить команды artisan:
php artisan vendor:publish --tag="avxman-ratings-config"
,
php artisan vendor:publish --tag="avxman-ratings-migrate"
и после php artisan migrate
.
Это установит таблицу рейтинга для получения и сохранения данных.
Команды artisan
-
Выгружаем все файлы
-
Выгружаем миграционные файлы
-
Выгружаем файлы моделек
-
Выгружаем шаблонные файлы
- Выгружаем конфигурационные файлы
Методы
Дополнительные (очерёдность вызова метода - первичная)
setEnabled()
- перезаписываем вкл./откл. рейтинга определённой моделиsetIp()
- перезаписываем Ip адрес пользователяsetUserAgent()
- перезаписываем User agent пользователяsetType()
- перезаписываем тип рейтингаsetView()
- перезаписываем шаблоны рейтингаsetModelName()
- перезаписываем модель рейтингаsetModelUserName()
- перезаписываем модель рейтинга пользователяsetExceptModel()
- перезаписываем исключение моделей, которые не будут участвовать в рейтингеreset()
- сбор параметров рейтингаИнициализация или сохранение рейтинга (очерёдность вызова метода - второстепенная)
isError()
- найдена ли ошибка или отключён рейтингgetOne()
- получение рейтинга одиночного результата из моделиgetMany()
- получение рейтинга множественного результата из моделиsave()
- сохранение рейтинга определённой моделиВывод (очерёдность вызова метода - последняя, при условии одиночной модели)
toCollection()
- получаем результат в виде коллекцииtoArray()
- получаем результат в виде массиваtoJson()
- получаем результат в виде jsontoHtml()
- получаем результат в виде html
Использование метода getMany()
При использовании данного метода в классе модели которую привязываем
к рейтингу нужно добавить трейт Avxman\Rating\Traits\RatingModelTrait
.
Когда в модели уже ранее Вами был написан метод rating()
,
тогда его нужно переименовать, так как трейт использует данный метод
Использование метода save($collection, $isPermission):bool
Метод может наследовать Дополнительные методы (очерёдность первичная)
перед вызовом save()
К примеру:
\Avxman\Rating\Facades\RatingFacade::save(collect([
'model'=>\App\Models\User::class,
'model_id'=>'1',
'rating'=>'1'
]));
\Avxman\Rating\Facades\RatingFacade::save(collect([
'model'=>\App\Models\AnyModel::class,
'model_id'=>'1',
'rating'=>'1',
'type'=>'five'
]), true);
$collection
- коллекция входных данных ['model'=>string,'model_id'=>string|int,'rating'=>string|int,'type'=>string]
model
- имя модели;
model_id
- ID модели;
rating
- оценка рейтинга;
type
- тип рейтинга,type_list
данные из ключа конфигурационного файла rating.php.
Обязательных данных['model','model_id','rating']
$isPermission
- [false, true]
false
- сохраняем рейтинг, при условии, что рейтинг с указанной моделью уже существует в таблице рейтингов
true
- сохраняем рейтинг в любом случаи, даже при отсутствии модели в таблице рейтингов. При отсутствии - создается новая запись в таблице (будьте осторожны, так как можно записать не существующую модель)return bool
- возвращает логический результат, при удачной записи - true