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

You can use controller routing :)

class UserController extends BaseController {

    /**
     * Instantiate a new UserController instance.
     */
    public function __construct()
    {
        $this->beforeFilter('@filterRequests');
    }

    /**
     * Filter the incoming requests.
     */
    public function filterRequests($route, $request)
    {
        //
    }

}
Last updated 2 years ago.
0

rcrocks said:

You can use controller routing :)

This still doesn't solve the problem.

I managed to create a work around for the problem

I put the query logic in my model and cache the result

public function scopeByUrl($query, $url)
{
	// cache the data for 15 minutes
	return Cache::remember('domain_by_url_'.$url, 15, function() use ($query, $url)
	{
		return $query->with('account.domains')->where('url', '=', $url)->first();
	});
}

and request it in both the filter and controller like so

$domain = Domain::byUrl(Request::server('HTTP_HOST'));

By caching the result the queries do not run twice... I wonder if I could store the result in the model though...

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Clooner clooner Joined 9 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.