PHP code example of vdauchy / laravel-routing-extender
1. Go to this page and download the library: Download vdauchy/laravel-routing-extender library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vdauchy / laravel-routing-extender example snippets
// In Routes/web.php:
Route::optionalParameterGroup('hreflang', '^[a-z]{2}(?:\-[a-z]{2})?$', ['as' => 'Hreflang::'], function () {
Route::get('home')->name('home');
});
// In YourCode.php:
route('Hreflang::home', []); // Will return `/home`
route('Hreflang::home', ['hreflang' => 'en-us']); // Will return `/en-us/home`
// In xxxProvider.php
URL::macro('customRouteResolver', function($name, $parameters, $absolute): ?\Illuminate\Routing\Route {
if ($name instanceof CustomClassA::class) {
return $name->getRoute();
}
if ($name instanceof CustomClassB::class) {
return $name->generateRoute();
}
return null;
});
// In YourCode.php:
route($instanceClassA); // Will generate the url from the Route object return by `$instanceClassA->getRoute()`
route($instanceClassB); // Will generate the url from the Route object return by `$instanceClassB->generateRoute()`
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.