-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RouteParameter attribute (#53080)
- Loading branch information
1 parent
3c501ee
commit 3818c2a
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Illuminate\Container\Attributes; | ||
|
||
use Attribute; | ||
use Illuminate\Contracts\Container\Container; | ||
use Illuminate\Contracts\Container\ContextualAttribute; | ||
|
||
#[Attribute(Attribute::TARGET_PARAMETER)] | ||
class RouteParameter implements ContextualAttribute | ||
{ | ||
/** | ||
* Create a new class instance. | ||
*/ | ||
public function __construct(public string $parameter) | ||
{ | ||
} | ||
|
||
/** | ||
* Resolve the route parameter. | ||
* | ||
* @param self $attribute | ||
* @param \Illuminate\Contracts\Container\Container $container | ||
* @return mixed | ||
*/ | ||
public static function resolve(self $attribute, Container $container) | ||
{ | ||
return $container->make('request')->route($attribute->parameter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters