V
V
Vladimir Singhtlov2017-01-16 14:41:14
Laravel
Vladimir Singhtlov, 2017-01-16 14:41:14

How to correctly transfer from one model to another Laravel?

Now there is middleware

public function handle($request, Closure $next)
    {
        $storeId = Store::id();
        if (empty($storeId)) {
            abort(404);
        }
        return $next($request);
    }

store model
static function id(){

        $domain = $_SERVER['SERVER_NAME'];
        if (!empty(Store::select('*')->where('domain', $domain)->first())) {
            $store = Store::select(['id'])->where('domain', $domain)->first()->toArray();
            return $store['id'];
        } else {
            return false;
        }
    }

category model
public function __construct(array $attributes = [])
    {
        $stoteId = Store::id();
        $this->table = $stoteId . '_category';
        parent::__construct($attributes);
    }

In this case, with each request to the model, the domain, a bunch of requests, will be checked.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrzej Wielski, 2017-01-16
@wielski

Indeed, why just write store_id in the category table. Let's spawn dozens of tables for each virtual store! Uhhh, how great it will be when there are under 100 stores in the database. Just a couple of thousand tables, spit it out. This will be easy to figure out!
Now, no sarcasm.
Urgently remake the structure of your database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question