Skip to content

Commit ba8af9e

Browse files
committed
Added wheres method to PendingResourceRegistration and test for it.
1 parent 3fe84d0 commit ba8af9e

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/Illuminate/Routing/PendingResourceRegistration.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,19 @@ public function shallow($shallow = true)
182182
return $this;
183183
}
184184

185+
/**
186+
* Add wheres to the resource routes.
187+
*
188+
* @param mixed $wheres
189+
* @return \Illuminate\Routing\PendingResourceRegistration
190+
*/
191+
public function wheres($wheres)
192+
{
193+
$this->options['wheres'] = $wheres;
194+
195+
return $this;
196+
}
197+
185198
/**
186199
* Register the resource route.
187200
*

src/Illuminate/Routing/ResourceRegistrar.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@ protected function getResourceAction($resource, $controller, $method, $options)
393393
$action['excluded_middleware'] = $options['excluded_middleware'];
394394
}
395395

396-
if (isset($options['where'])) {
397-
$action['where'] = $options['where'];
396+
if (isset($options['wheres'])) {
397+
$action['where'] = $options['wheres'];
398398
}
399399

400400
return $action;

tests/Routing/RouteRegistrarTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,22 @@ public function testResourceWithoutMiddlewareRegistration()
525525
$this->assertEquals(['one'], $this->getRoute()->excludedMiddleware());
526526
}
527527

528+
public function testResourceWheres()
529+
{
530+
$wheres = [
531+
'user' => '\d+',
532+
'test' => '[a-z]+',
533+
];
534+
535+
$this->router->resource('users', RouteRegistrarControllerStub::class)
536+
->wheres($wheres);
537+
538+
/** @var \Illuminate\Routing\Route $route */
539+
foreach ($this->router->getRoutes() as $route) {
540+
$this->assertEquals($wheres, $route->wheres);
541+
}
542+
}
543+
528544
public function testCanSetRouteName()
529545
{
530546
$this->router->as('users.index')->get('users', function () {

0 commit comments

Comments
 (0)