Closed arcanedev-maroc closed 4 years ago
This seems related to #9 (Improve Typecasting)
I agree an empty collection may make sense in this situation. But haven't thought through it fully.
+1
@arcanedev-maroc when could we expect PR for this?
It would make sense to add a not-null collection cast (another cast) for this feature to allow code to check for null values vs empty collections. Different models (or same model in different context) may behave differently.
I created PR to close this issue :)
It's a shame that this idea was not implemented yet.
Yes a great idea, my +1 on it 👍
Any news on that? Sounds really great.
Is this going to get implemented :)?
@arcanedev-maroc, if I understand your problem correctly, the changes proposed in laravel/framework#30958 will make it easy to solve.
I'm wondering if it's a good idea to return an empty
Collection
object instead ofnull
when we specify a casting like this:This will avoid us to add more checks like
is_null($this->keywords)
. And it's views friendly when you do something like this{{ $meta->keywords->implode(', ') }}
.And for if statement, i prefer to do something like
@if ($meta->keywords->isEmpty())
than@if (is_null($meta->keywords))
.So, my PR will be something like this (At this section on
master
branch):We can also add
array
to the casts instead returning anull
value.cc: @taylorotwell @themsaid @GrahamCampbell