Hi! I am creating a second project for a company.
The first one was written by me in Yii framework. Now I want to switch into Laravel.
In Yii, in model, I have beforeFind and beforeSave functions in ActiveRecord. I can't see it in Laravel. Why I need this? I need to create application with different shops. Shops can be added to users. User "user1" has 3 shops: shop1, shop2, shop3. In menu I want to have Change shop and then user can switch the shop and all showed, added, deleted data should belongs to that shop. User can't see anything from shop 4. I want to automate this to not remember every time to add condition shop_id = XXX.
In beforeSave I want to add shop_id to every object.
Also I need some models to be global for all shops (ie. global settings, users).
How can I achieve this in Laravel?
Thank's for all advices
A session wouldn't work somehow?
Could you dig into yii and see how they accomplished it?
I save in session while loging user shop_id, and when switching shop I save shop_id in session too. In Yii there is function BeforeSave and BeforeFind in ActiveRecord and I create my own MyActiveRecord : ActiveRecord with beforeSave and BeforeFind method. In this method I add compare to CdbCriteria ($crtiteria->compare('shop_id', $session['shop_id']) and then call parent find.
I need someting like this in Laravel :)
When you say menu, you do mean a menu in the view. If that is the case, could the user shops (other pages) be recorded in the database, then in menu use a dropdown to select a different shop, make links in the dropdown. Or you could have tabbed links at top or bottom of page. Are the shops other pages, or exactly what?
I need to call Product:all() and get only products connected with specific shop (saved in session). Products has shop_id attribute.
Look at this thread:
http://laravel.io/forum/12-12-2014-eloquent-relations-problem
Chaining wheres.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community