Dynamic caching for website speed!

Submitted by haruncpi - 4 years ago

Make your dynamic post caching for load your website post fast.

Route::get('/{slug}','SiteController@postDetails');

//Example URL: example.com/awesome-post-title
public function postDetails($slug){
	
	$post = Cache::remember('posts.'.$slug, function($slug) use($slug) {
    	    return Post::where('slug',$slug)->first();
	});

	return view('frontend.posts.post-details',['post'=>$post]);
}

To read more: https://bit.ly/speed-up-laravel-website