Comments (5)
That's it, ty very much. +1
Route::any('{all}', function(){
return 'It Works';
})->where('all', '.*');
from framework.
Firstly, a 404 in L4 is handled by catching a Symfony\Component\HttpKernel\Exception\HttpNotFoundException
so that's how you handle your 404's.
How you do the same in L4 is by appending where()
after the declaration of a route, where the first parameter is the named param in the route and the second param is a regular expression which must match true. If it does not, the route is not executed and another match is found (if it exists). For example (don't quote me on syntax errors :P):
<?php
// GET /foo/123/some/other/value/here
// GET /foo/a123/sdf will not work as "a123" is not numeric.
Route::get('foo/{bar}/{baz}', function($bar, $baz)
{
// $bar == 123
// $baz == 'some/other/value/here'
})->where('bar', '\d+') // Digits
->where('baz', '.*'); // Anything
// You can modify your REGEX to suit:
// GET /foo/a123/asdf
// GET /foo/z123/asdf
// GEt /foo/df123/asdkfjsd
Route::get('foo/{bar}/{baz}', function($bar, $baz)
{
})->where('bar', '[a-z]{1,2}\d+') // 1-2 Letters + Digits
->where('baz', '.*'); // Anything
Have a look at http://symfony.com/doc/2.0/components/routing/introduction.html for more as L4 uses the Symfony routing as it's backbone.
Also, check out http://gskinner.com/RegExr/ for a really intuitive way to build up regular expressions :)
from framework.
No problem, glad I could help.
I was a bit disappointed to see (:all) go at first until I saw the potential of this solution!
I'd recommend closing the issue now :)
from framework.
This is covered in the Laravel docs at four.laravel.com is it not? Also, @jasonlewis has a great blog post on this issue.
from framework.
None of the above works in Laravel 4.0. Here is the solution:
Route::any('{firstPart}/{rest}', function($firstPart, $rest){
return Response::make($firstPart . ", " . $rest);
})->where('firstPart', '[^/]*')->where('rest', '.*');
from framework.
Related Issues (20)
- Event Auto Discovery not working with vendor package HOT 3
- Exceptions render is not being called for some Laravel and Symfony exceptions HOT 3
- Passport issue in laravel 11 HOT 4
- Issues with Testing and Routing After Upgrading to Laravel 11.0 HOT 1
- Unexpected newline behavior in blade template with echo followed by verbatim HOT 4
- Null Parameter Deprecation Notices HOT 1
- `Bus::dispatch()` cannot be used to queue closures HOT 1
- Throttle middleware with unnamed limiters behave weirdly HOT 3
- Escaped PHP code rendered instead of section contents in Blade template HOT 2
- Enable broadcasting after upgrade Laravel from 10.x to 11.x HOT 1
- Default connection is being changed unreliably in testing HOT 1
- The `Paginator` interface does not implement `through` method HOT 1
- Route file is broken when use a method to define return
- Maria DB before 10.5.2 rename nullable column fails HOT 5
- Container unable to resolve class in a Job class HOT 1
- /Support/Facades/Schedule.php failing pipeline HOT 1
- Pagination with SQL Server driver returns duplicate records on subsequent pages HOT 1
- Redirect guests is hard coded to route('login') HOT 4
- fruitcake/php-cors v13 needed but not match HOT 1
- Php artisan test "Option --configuration cannot be used more than once" HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from framework.