laravel-41-route-caching
laravel-41-route-caching copied to clipboard
Is there any way we can call this multiple times in route.php
My route.php is quite long and it contains several Route::group. If the Route::cache(FILE, function() {}); function support multiple call then it would great.
Not currently, no. Is there any particular reason you can't wrap all Route::group
calls in a single Route::cache
?
let's say, I have a route.php like in the attachment (route.txt) route.txt
How should I call the cache?
You could wrap the entire file in a Route::cache
call, like this:
Route::cache(__FILE__, function() {
// Landing page
Route::get('/', 'IndexController@getIndex');
Route::get('/about/us/', 'IndexController@aboutus');
Route::get('/for/teacher/', 'IndexController@forteacher');
Route::get('/for/student/', 'IndexController@forstudent');
// Teacher group
Route::group(['prefix' => 'teacher', 'namespace' => 'Teacher'], function () {
// ...
});
// Student group
Route::group(['prefix' => 'student', 'namespace' => 'Student'], function () {
// ...
});
});
If, for whatever reason, that doesn't work for you, could adjust the __FILE__
parameter. This is used as the cache key, so you could, in the same file, first call Route::cache(__FILE__ . 1, function() { });
, Route::cache(__FILE__ . 2, function() { });
, and so forth.
I hope that helps!
I tried 2nd way but in my view I used laravel action() method like {{ action('Doc\DocumentController@index') }}
And I received this error in laravel.log:
Error in exception handler: Route [Doc\DocumentController@index] not defined.
Here is the sample route.php route.php