Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Jenny Swift
Jenny Swift
21,999 Points

How to use Laravel Throttle

Hi, I am trying to use Laravel Throttle but am having trouble getting it work and wondering if someone could please help me?

I've followed the installation and configuration instructions. But when I try the following example code from the docs (replacing 'foo' with my own path, and using smaller numbers for the throttle parameters), it doesn't seem to work:

use Illuminate\Support\Facades\Route;

Route::get('foo', array('before' => 'throttle:50,30', function () {
    return 'Why herro there!';
}, ));

I have also tried this other example from the docs, and each time I refresh the page, count($throttler) is still 1:

use GrahamCampbell\Throttle\Facades\Throttle;
use Illuminate\Support\Facades\Request;

// let's quickly get the current request object
$request = Request::getFacadeRoot();

// now let's get a throttler object for that request
// we'll use the same config as in the previous example
// note that only the first parameter is "required"
$throttler = Throttle::get($request, 50, 30);

// let's check if we've gone over the limit

// we implement Countable

I'm assuming $thottler is a typo in the example and should be $throttler.

I figure count($throttler) should increment each time I load the page? But I'm not sure how to get it to do that.