Comments (1)
I managed to implement a withSetting
scope like so.
I updated the migration to use a json
type column instead of the default text
column.
Schema::table('users', function(Blueprint $table)
{
$table->json('settings');
});
I then created a scope on my User
model.
/**
* Scope User's With Setting
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $setting
* @param string $value
* @return \Illuminate\Database\Query\Builder
*/
public function scopeWithSetting($query, $setting, $value = true)
{
return $query->where('settings->' . str_replace('.', '->', $setting), $value);
}
I can then fetch Users with a specfic setting like so.
$users = User::withSetting('emails.weekly', 'on')->get();
Hope this helps anyone planning on doing this theirselves.
from laravel-user-settings.
Related Issues (20)
- Function forget not making dirty
- Booleans are stored as strings HOT 5
- SQL Syntax error if user is not authenticated HOT 4
- Change SETTINGS type from STRING to TEXT HOT 3
- Is this Repository still active? HOT 2
- No Json supported. Can you change to text or provide alternative? HOT 16
- Support for GUID/UUIDs
- Empty column error HOT 1
- Readme should suggest text instead of varchar
- Class setting does not exist HOT 1
- Update package to support Laravel 5 HOT 1
- Laravel 6 Support? HOT 5
- How to get Settings from specific user? HOT 1
- Set a license for the project
- This package clashes with anlutro/laravel-settings (global settings)
- ServiceProvider not found HOT 2
- Setting::forget Not working HOT 2
- How can I retrive the authenticated user Id in the ConfigServiceProvider? HOT 1
- Laravel 5.2 Error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-user-settings.