Category : session

I need to store a session variable in my app. In the Laravel controller I do something like this: if (!session(‘xyz’)) { session([‘xyz’ => ‘ABC’]); } Since I’m using Inertia, I render the component like: return Inertia::render(‘Comp’) ->with(‘xyz’, session(‘xyz’)); Then in the componet I read the session variable with this.$page.props.xyz The code works, but since ..

Read more

This is my Controller Session variable generated in set_value function are not accessible inside function get_value. This code works fine on my localhost, but not working on server. All session related files are same are laravel documentation. Laravel version is 7. public function set_value(Request $request){ session_start(); Session::put(‘name’, ‘Hello World’); } public function get_value(){ $data = ..

Read more

My application is laravel 8.75.0 in the backend serving apis requests for a react frontend. I am using session to authenticate users, and to store session variables. On production, react is built, and served statically using apache. Links are: http://123.123.123.123/api -> backend laravel routes http://123.123.123.123/dashboard -> react build folder The production really doesn’t use a ..

Read more

I’m working with Laravel 5.8 and LaravelExcel for importing some unique National Codes of users into the database. So I coded this at the Import Class: $ncodes = DB::table(‘olympiad_1400’)->select(‘mys_ncode’)->get(); $n = 0; $moghayerat = []; foreach($formatArray as $arr){ if($ncodes[$n]->mys_ncode == $arr[‘nationalCode’]){ DB::table(‘olympiad_1400’)->insert([ ‘mys_object_id’ => $objectId, ‘mys_object_type_id’ => $objectTypeId, ‘mys_olp_id’ => 4, ‘mys_name’ => $arr[‘name’], ‘mys_fname’ ..

Read more

Laravel login not working but showing the below intermediate page It happens only in the production server which is an oracle cloud instance with docker on it and working after server restart and again returns back after some hours. My docker-compose file is version: ‘3’ networks: laravel: services: nginx: build: context: . dockerfile: nginx.dockerfile ports: ..

Read more

i have created session user_name and user_id that can contain record of current login user but in both session 1 is stored . i dont know how it 1 is stored in both session. if i print both sessions its shows 1. public function login(Request $request){ $request->validate([ ’email’=>’required’, ‘password’=>’required’ ]); $email=$request->post(’email’); $password=$request->post(‘password’); $result=User::where([’email’=>$email,’status’=>’1′])->get(); if(isset($result[0])){ $db_pass=$result[0]->password; ..

Read more

Let’s say, I created 2 server and 4 sub domains. example.com and first.example.com route to first server. second.example and third.example.com route to second server, different database. The sessions are stored in database. If I change SESSION_DOMAIN in .env to .example.com and login to first server from example.com, the session is reused in first.example.com, too. However, ..

Read more

I am in a troble, I need to use a session table, this table is used for several aplications so it’s diffucult to change the primary key that is session_id, for default laravel uses like primary key a fiel called id, but in this case i need to used a different name (session_id), somebody know ..

Read more

I’m working with Laravel 5.8 and I wanted to make sure that users can submit a form only every 2 hours (as long as a session is alive). So I tried this at the Controller: if(Session::has(‘request_has_been_sent’)){ return redirect()->back()->with(‘error’, ‘You just submitted a request and cannot submit a new one’); }else{ $withDraw = WithdrawWallet::create([ ‘balance_value’ => ..

Read more

So, i want to make if else statement where if $cart session has different sponsor_id value, users cannot add product from another sponsor_id heres my CartController public function addToCart(Request $request, $id) { $cart = session("cart"); $produk = Produk::detail_produk($id); if (isset($cart[$id])) { $cart[$id]["qty"]++; session()->put(‘cart’, $cart); } else { $cart[$id] = [ "sponsor_id" => $produk->sponsor_id, "nama_produk" => ..

Read more

I created a classic Validation Request class. <?php namespace AppHttpRequests; use IlluminateFoundationHttpFormRequest; class StoreCattleTypeRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return true; } /** * Get the validation rules that apply to the request. * * @return ..

Read more

I am trying to define a variable using data from the session, and then share that variable with all views. The answer seems to be creating a middleware. I am struggling to do this. First, here is the code from a middleware file, GetCart.php namespace AppHttpMiddleware; use Closure; use IlluminateHttpRequest; use IlluminateSupportFacadesSession; use IlluminateSupportFacadesView; class ..

Read more