Answers for "session based condition not working in construct in laravel controller"

PHP
0

session based condition not working in construct in laravel controller

//**************** Solution in laravel ********************************//
// Add This three line in kernal.php in $middleware laravel varsion 7 or above
protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    \Illuminate\Session\Middleware\StartSession::class,
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
];

// In Cunstruct function in controller 
protected $list_limit;
protected $start_page_serial_number;

public function __construct(){
  	$this->AdminAdvanceModel = new AdminAdvanceModel();
  	if(empty(Session::get('list_limit'))) {
    	$this->list_limit = 25;
  	} else {
    	$this->list_limit = Session::get('list_limit');
  	}
  	if(empty(Session::get('start_page'))) {
    	$this->start_page_serial_number = 0;
  	} else {
    	$this->start_page_serial_number = (Session::get('start_page')-1)*$this->list_limit;
  	}
}

/* After This Changes Restart Laravel Set (PHP Artisan serve) command to restart 
laravel setup Logout or forget all session in laravel After That Login again */
Posted by: Guest on September-22-2021

Code answers related to "session based condition not working in construct in laravel controller"

Browse Popular Code Answers by Language