session based condition not working in construct in laravel controller

Solutions on MaxInterview for session based condition not working in construct in laravel controller by the best coders in the world

showing results for - "session based condition not working in construct in laravel controller"
Nele
23 Sep 2016
1//**************** Solution in laravel ********************************//
2// Add This three line in kernal.php in $middleware laravel varsion 7 or above
3protected $middleware = [
4    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
5    \Illuminate\Session\Middleware\StartSession::class,
6    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
7];
8
9// In Cunstruct function in controller 
10protected $list_limit;
11protected $start_page_serial_number;
12
13public function __construct(){
14  	$this->AdminAdvanceModel = new AdminAdvanceModel();
15  	if(empty(Session::get('list_limit'))) {
16    	$this->list_limit = 25;
17  	} else {
18    	$this->list_limit = Session::get('list_limit');
19  	}
20  	if(empty(Session::get('start_page'))) {
21    	$this->start_page_serial_number = 0;
22  	} else {
23    	$this->start_page_serial_number = (Session::get('start_page')-1)*$this->list_limit;
24  	}
25}
26
27/* After This Changes Restart Laravel Set (PHP Artisan serve) command to restart 
28laravel setup Logout or forget all session in laravel After That Login again */
29