Using Laravel as a PHP development framework has been a long time, but some of the official documents are not covered in the place, and will be forgotten at intervals. Recently done a bit of simple finishing, conveniently record the memo.
1. Route::controller Route naming:
Route::controller can reduce a lot of work in routing customization, but sometimes it is necessary to name a particular route to use, but the Route::controller method is to specify the route of all the methods in a controller, how to name it? You can use the third argument in controller ($uri, $controller, $names = Array ()), which is an array, the key of the array is the method, and the value of the array is named.
Copy Code code as follows:
The signature of the function:
Public Function controller ($uri, $controller, $names = Array ())
Do not name general use:
Route::controller (' admin ', ' admincontroller ');
You need to name some of these methods:
Route::controller (' admin ', ' Admincontroller ', Array (
' GetIndex ' => ' Admin.index ',
' GetLogin ' => ' Admin.login ',
' Postlogin ' => ' Admin.login '
));
2. According to system variables to determine the current operating environment
The way the system defaults to determine whether the local environment is based on specifying a set of host names in the ' local ' array as the native environment, such as working on an office machine, a MacBook, and you're going to write two host names, I think it's a hassle. To be judged according to $_server[' Laravel_env ', so that I can define ' laravel_env ' environment variables in all the development machines, ' local ', and then automatically recognize the ' local ' environment in the development machine, while others are ' Production '.
Copy Code code as follows:
The default is to determine whether the local environment is based on the host name
$env = $app->detectenvironment (Array (
' Local ' => array (' Homestead ');
));
Modify to determine whether the system variable is specified, not to determine the host name
$env = $app->detectenvironment (function () {
$_env = getenv (' laravel_env ')? getenv (' laravel_env '): Array (
' Local ' => array (' Homestead ')
);
return $_env;
});
This is actually going to read the value of $_server[' laravel_env '
In Apache, you can use the setenv setting,
In Nginx, you can use the Fastcgi_param setting