Comments (5)
Could there be any instances where you might want laravels 'dumb' casting of JSON data to an array/object for a column and not this package? Or would should another cast be introduced? e.g. jsond
?
from dialect.
Ah, looking at the code it wouldn't actually be possible to use this property, the part of Laravel that deals with it...
/**
* Cast an attribute to a native PHP type.
*
* @param string $key
* @param mixed $value
* @return mixed
*/
protected function castAttribute($key, $value)
{
if (is_null($value)) return $value;
switch ($this->getCastType($key))
{
case 'int':
case 'integer':
return (int) $value;
case 'real':
case 'float':
case 'double':
return (float) $value;
case 'string':
return (string) $value;
case 'bool':
case 'boolean':
return (bool) $value;
case 'object':
return json_decode($value);
case 'array':
case 'json':
return json_decode($value, true);
default:
return $value;
}
}
Doesn't call any external methods or provide any way to add new casts. The only way would be to override the method...
Actually, that might work out okay, but possibly not the best solution.... hmm
from dialect.
Conclusion on this? Looking to close out or implement if there's something to do here...
from dialect.
My first comment was confusing, please note that you can cast to json too (thanks to @EspadaV8)
You could do:
public function inspectJsonColumns()
{
// merge jsonColumns with cast property
$casted = array_keys(array_where($this->casts, function($k, $v) {
return ($v === 'json')
}));
$this->jsonColumns = array_merge($this->jsonColumns, $casted);
foreach ($this->jsonColumns as $col) {
$this->hidden[] = $col;
$obj = json_decode($this->$col);
if (is_object($obj)) {
foreach ($obj as $key => $value) {
$this->flagJsonAttribute($key, $col);
$this->appends[] = $key;
}
}
}
}
from dialect.
This looks dead but if there is still a need please re-open or submit pull request. Thanks!
from dialect.
Related Issues (8)
- Why is Ardent required? HOT 1
- Laravel 5.1 issue HOT 5
- Migration file HOT 1
- Nice work - Any way to query on a json value? HOT 1
- Is there a way to define many to many (or any other than one to one) relationships? HOT 3
- Model::create($attributes) doesn't work HOT 5
- Why does the readme state "only supports PostgreSQL" HOT 5
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 dialect.