Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Define route regular expression constraints #34361

Closed
wants to merge 2 commits into from
Closed

[8.x] Define route regular expression constraints #34361

wants to merge 2 commits into from

Conversation

gregorip02
Copy link
Contributor

This allows us to define constraints for routes using whose regular expression is sometimes repetitive.

Instead of having something like this

<?php

Route::get('/articles/{user}/{slug}')->where(['user' => '[0-9]+', 'slug' => '[A-Za-z]+']);

We would have something simpler like this.

<?php
Route::get('/articles/{user}/{slug}')->whereNumber('user')->whereAnyChar('slug');

Regular expression constraint methods added

<?php

Route::get('/posts/{post}')->whereNumber('post');

Route::get('/posts/{post}')->whereAnyChar('post');
Route::get('/posts/{post}')->whereLowerChar('post');
Route::get('/posts/{post}')->whereUpperChar('post');

Route::get('/search/{search}')->whereSlash('search');

@GrahamCampbell GrahamCampbell changed the title [8.x] Define route regular expression constraints. [8.x] Define route regular expression constraints Sep 15, 2020
@taylorotwell
Copy link
Member

The general idea is not bad but I'm not I understand whereSlash... maybe I don't understand the naming. I'm also not sure whereLowerChar and whereUpperChar would be very useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants