Closed pierrocknroll closed 5 years ago
Probably the "right" way to do this is to use Eloquent Resources if you are running Laravel 5.5, or something like Fractal if you aren't.
In order to do it "natively", you'd need to extend the package's Tag
class and add a toJson()
method on it. The current version of the package doesn't make this easy, but it's on my to-do list for the next major version (although there is no ETA for that right now).
(Leaving this open as a reminder for me.)
Thanks for the answer ! For now I've made something like this in my Model :
public function toArray()
{
$array = parent::toArray();
if (isset($array['tags'])) {
foreach ($array['tags'] as &$tag) {
unset($tag['created_at'], $tag['updated_at'], $tag['pivot']);
}
}
return $array;
}
Not very pretty but I can live with it.
Just looking over old issues ... I said:
In order to do it "natively", you'd need to extend the package's
Tag
class and add atoJson()
method on it.
The package does allow you to change the Tag
class to your own implementation, so this should be trivial to do now. I don't know why I mention this at the time I made that change, but I'm closing the issue now since it should be doable.
Hi, Thanks a lot for your great package !
My Laravel is an API, and I want to return the tags associated with my Model so I've made :
in my Model.
So a response from my API looks like :
But I want to hide the created_at, updated_at and pivot fields, is it possible without modifying your package ? Thanks !