All Projects → Taronyuu → Laravel User Settings

Taronyuu / Laravel User Settings

Licence: mit
Simple and persistent boolean settings per user

Projects that are alternatives of or similar to Laravel User Settings

Ip Location Zh
获取 IP 地址的真实地理位置
Stars: ✭ 556 (+1535.29%)
Mutual labels:  laravel, laravel-5-package
Laravel Widgetize
A minimal package to help you make your laravel application cleaner and faster.
Stars: ✭ 791 (+2226.47%)
Mutual labels:  laravel, laravel-5-package
Laravel Mysql Spatial
MySQL Spatial Data Extension integration with Laravel.
Stars: ✭ 578 (+1600%)
Mutual labels:  laravel, laravel-5-package
Laravel Scout Mysql Driver
Laravel Scout MySQL Driver
Stars: ✭ 491 (+1344.12%)
Mutual labels:  laravel, laravel-5-package
Socialite Mailru
MailRu OAuth2 Provider for Laravel Socialite
Stars: ✭ 25 (-26.47%)
Mutual labels:  laravel, laravel-5-package
Column Sortable
Package for handling column sorting in Laravel 5/6/7/8
Stars: ✭ 496 (+1358.82%)
Mutual labels:  laravel, laravel-5-package
Orm
A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen
Stars: ✭ 712 (+1994.12%)
Mutual labels:  laravel, laravel-5-package
Laravel Server Monitor
Server Monitoring Command for Laravel Applications
Stars: ✭ 424 (+1147.06%)
Mutual labels:  laravel, laravel-5-package
Laravel Tools
路飞laravel工具
Stars: ✭ 24 (-29.41%)
Mutual labels:  laravel, laravel-5-package
Identity Number
Validator for Swedish personal identity numbers (personnummer). For use "standalone" or with Laravel.
Stars: ✭ 17 (-50%)
Mutual labels:  laravel, laravel-5-package
Laravel Js Localization
🌐 Convert your Laravel messages and consume them in the front-end!
Stars: ✭ 451 (+1226.47%)
Mutual labels:  laravel, laravel-5-package
Laravel Test Factory Helper
Generate Laravel test factories from your existing models
Stars: ✭ 873 (+2467.65%)
Mutual labels:  laravel, laravel-5-package
Telegram
✈️ Telegram Notifications Channel for Laravel
Stars: ✭ 450 (+1223.53%)
Mutual labels:  laravel, laravel-5-package
Sudo Su
Laravel package to easily login as other users during development.
Stars: ✭ 554 (+1529.41%)
Mutual labels:  laravel, laravel-5-package
Lada Cache
A Redis based, fully automated and scalable database cache layer for Laravel
Stars: ✭ 424 (+1147.06%)
Mutual labels:  laravel, laravel-5-package
Laravel Video Chat
Laravel Video Chat using Socket.IO and WebRTC
Stars: ✭ 646 (+1800%)
Mutual labels:  laravel, laravel-5-package
Generator
Laravel 5.3+ Scaffold Generator, Support both bootstrap and Semantic UI
Stars: ✭ 327 (+861.76%)
Mutual labels:  laravel, laravel-5-package
Laravel Translation
Translation management for your Laravel application.
Stars: ✭ 350 (+929.41%)
Mutual labels:  laravel, laravel-5-package
Angular5.2 Laravel5.6
Angular 5.2 and Laravel 5.6 Authentication and CRUD
Stars: ✭ 17 (-50%)
Mutual labels:  laravel, laravel-5-package
Improved Polymorphic Eloquent Builder
🔨 Improved Polymorphic Eloquent Builder
Stars: ✭ 12 (-64.71%)
Mutual labels:  laravel, laravel-5-package

Laravel user settings

Simple and persistent boolean settings per user.

Build Status MIT Licence PRs Welcome

This package has been developed to help you store simple boolean settings (true/false or yes/no settings) per user.

Features

  • Only 1 additional column for multiple settings.
  • Settings are stored as binary.
  • Can be used on all models.
  • Customizable.
  • Fast.

Background

Laravel user settings only requires 1 additional column (bigint) per entity. All settings are stored in this column as a binary value. By using the bitwise operators in PHP we are able to store multiple settings in a single column without extra coding/decoding or multiple queries.

Searching for enabled settings is supported by MySQL as can be found here.

Usage

Get a setting

$user->setting('my_setting');

OR

$user->getSetting('my_setting');

Set a setting

$user->setting('my_setting', true);

OR

$user->setSetting('my_setting', true);

Overriding a list of allowed setting for the entity. A global list of settings can be found in the user-settings.php config file, if you want to override these settings per model you can override the following method:

/**
 * getSettingFields function.
 * Get the default possible settings for the user. Can be overwritten
 * in the user model.
 *
 * @return array
 */
public function getSettingFields()
{
    return config('user-settings.setting_fields', []);
}

Searching for settings in a query

$user = (new User())->whereSetting('my_setting')->first();

Set multiple settings at once

$user->setMultipleSettings([
    'my_setting'        => true,
    'my_setting_2'      => false,
]);
$user->save();

Installation

First of all you should require the package using composer:

composer require internetcode/laravel-user-settings

Afterwards you can add the service provider to your providers array. This is optional since it is already auto discovered by Laravel.

'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
        Illuminate\Auth\AuthServiceProvider::class,

        ...

        Internetcode\LaravelUserSettings\LaravelUserSettingsServiceProvider::class,
    ],

Publish the config and migration files.

php artisan vendor:publish --tag=config
php artisan vendor:publish --tag=migrations

Please note that the newly created migration file defaults to a settings column on the user model. Feel free to change that, or add multiple tables.

On the models where you want to use the settings add the HasSettingsTrait trait.

<?php

namespace Internetcode\LaravelUserSettings\Tests;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Internetcode\LaravelUserSettings\Traits\HasSettingsTrait;

class User extends Authenticatable
{
    use HasSettingsTrait;

Caveats

  • Never change the order of the settings in the setting_fields array. Every field in here is converted based on the index of the field. Therefore changing the order/index of your setting, will result in invalid settings being true or false.

Bugs / Issues / Ideas

Please create an issue using the issue tracker or drop us an email.

License

MIT © Zander van der Meer

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].