You could take a look at Model Observers: http://laravel.com/docs/4.2/eloquent#model-observers
Or perhaps, depending on what you are trying to do Accessors: http://laravel.com/docs/4.2/eloquent#accessors-and-mutators
Hope it helps.
Hi,
thank you for your reply.
I want to avoid extra queries, so the only ways to do this is to select my extra column at initialization.
How are you dealing with URLs? Perhaps you could do something with a route filter?
Of if your users locale has been defined, you could use App::setLocale('en'); ? You could perhaps then use the locale as part of your queries?
There are a couple of threads on here that people have been discussing translations - Sadly. I can only offer a few ideas. Translations are in phase two for us!
Cheers
Hi you :)
Although my table name is translation, my problem is not about the localisation of an application. ^^
I want to execute a sub select and append the result as a property to my model.
I have the model JsonKey
, which needs an appended property calculated by a sub select.
select *, (select translations.updated_at from "translations" where "jsonkeys"."id" = "translations"."jsonkey_id" and "translations".language = "english") as master_updated_at from "jsonkeys"
The reason I don't want to use an accessor is to save database queries. Because I have a lot items.
So I came up with the idea, to manipulate the models initializing query to perform this sub select.
alexwenzel said:
Hi you :)
Although my table name is translation, my problem is not about the localisation of an application. ^^
I want to execute a sub select and append the result as a property to my model.
I have the model
JsonKey
, which needs an appended property calculated by a sub select.select *, (select translations.updated_at from "translations" where "jsonkeys"."id" = "translations"."jsonkey_id" and "translations".language = "english") as master_updated_at from "jsonkeys"
The reason I don't want to use an accessor is to save database queries. Because I have a lot items.
So I came up with the idea, to manipulate the models initializing query to perform this sub select.
Anyone got a solution / idea?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community