laravel-41-route-caching icon indicating copy to clipboard operation
laravel-41-route-caching copied to clipboard

Is there any way we can call this multiple times in route.php

Open rockmetoo opened this issue 7 years ago • 4 comments

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.

rockmetoo avatar Jun 15 '17 07:06 rockmetoo

Not currently, no. Is there any particular reason you can't wrap all Route::group calls in a single Route::cache?

MaartenStaa avatar Jun 15 '17 08:06 MaartenStaa

let's say, I have a route.php like in the attachment (route.txt) route.txt

How should I call the cache?

rockmetoo avatar Jun 15 '17 08:06 rockmetoo

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!

MaartenStaa avatar Jun 15 '17 08:06 MaartenStaa

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

rockmetoo avatar Jun 15 '17 14:06 rockmetoo