Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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?

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

alexwenzel alexwenzel Joined 19 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.