I want to put some values in session which are going to be usable on the whole website.
I first tried session global functions but they are not working.
then I tried SESSION facade.. session facade is storing values for controller.php but I am unable to retrieve that values in views. here is my controller.php code
<?php
namespace App\Http\Controllers;
use App\Currency;
use App\Option;
use Artesaos\SEOTools\Traits\SEOTools as SEOToolsTrait;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use SEOToolsTrait;
public $country,$currency,$user_lat,$user_lng;
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function __construct()
{
$this->current_page = isset($_GET['page']) ? intval($_GET['page']) : '';
$this->current_page_text = '_' . $this->current_page;
if (!\Session::has('user_latitude')) {
\Session::put('user_latitude', \Misc::ip_info(null, 'latitude'));
}
if (!\Session::has('user_longitude')) {
\Session::put('user_longitude', \Misc::ip_info(null, 'longitude'));
}
$user_lat = \Session::get('user_latitude');
$user_lng = \Session::get('user_longitude');
$this->user_lat = $user_lat !='' ? $user_lat : '30.8167';
$this->user_lng = $user_lng !='' ? $user_lng : '75.3333';
}
}
code to retrieve session values
alert('{{ session('user_latitude') }}');
I have used session facade also
Steps To Reproduce:
use session() functions or SESSION facade in controller.php
Description:
I want to put some values in session which are going to be usable on the whole website.
I first tried session global functions but they are not working. then I tried SESSION facade.. session facade is storing values for controller.php but I am unable to retrieve that values in views. here is my controller.php code
code to retrieve session values
alert('{{ session('user_latitude') }}');
I have used session facade also
Steps To Reproduce:
use session() functions or SESSION facade in controller.php