Skip to content

Commit b2c3f66

Browse files
committed
Merge branch 'api-resource-where-support' into 7.x
2 parents ed12061 + 3dcc4a6 commit b2c3f66

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/Illuminate/Routing/PendingResourceRegistration.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,19 @@ public function withoutMiddleware($middleware)
169169
return $this;
170170
}
171171

172+
/**
173+
* Add "where" constraints to the resource routes.
174+
*
175+
* @param mixed $wheres
176+
* @return \Illuminate\Routing\PendingResourceRegistration
177+
*/
178+
public function where($wheres)
179+
{
180+
$this->options['wheres'] = $wheres;
181+
182+
return $this;
183+
}
184+
172185
/**
173186
* Indicate that the resource routes should have "shallow" nesting.
174187
*

src/Illuminate/Routing/ResourceRegistrar.php

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

396+
if (isset($options['wheres'])) {
397+
$action['where'] = $options['wheres'];
398+
}
399+
396400
return $action;
397401
}
398402

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+
->where($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)