Ad
Laravel Varbinary(ip) Using With Where Not Working
I'm using varbinary(16) to store ips in the database like described here https://stackoverflow.com/a/24270808/5717102 .
To convert to human readable and to binary i use inet_ntop
and inet_pton
.
This works well, but it won't work with the where query.
MyModel::where('ip', $ip)->get();
What am I missing, shouldn't it work? I already googled, but wasn't able to find any usefull information.
Ad
Answer
Accessors and Mutators won't work with queries. So you should access it as MyModel::where('ip', inet_pton($ip))->get()
You can further just create a scope and move the logic to the model if you want to extract it out.
public function scopeWhereIp($query, $ip)
{
return $query->where('ip', inet_pton($ip));
}
and access it as
MyModel::whereIp($ip)->get()
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad