Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mozew's avatar
Level 6

How to update call Session

I have a project where the user first signs up. After registering a sms, the code will be sent to the user and in the database both the code and the mobile will be saved.

Of course, I saved before on the Session::put('mobile',$mobile) & Session::put('code',$code) registry page. How can I call it now?

So far I have no problem. And then after saving the button, it redirects to the verification code form. Here, the user must enter their mobile number and code.

Now, if the user changes the verification_code field to 1 after entering the mobile number and code.

Code

create_users.table

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->boolean('active')->default(false);
        $table->string('level')->default('user');
        $table->string('first_name');
        $table->string('last_name');
        $table->string('mobile');
        $table->string('code');
        $table->boolean('verification_code')->default(0);
        $table->string('birth_date');
        $table->boolean('gender');
        $table->bigInteger('province_id')->unsigned();
        $table->bigInteger('city_id')->unsigned();
        $table->text('address');
        $table->string('email')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();

        $table->foreign('province_id')->references('id')->on('provinces')->onDelete('cascade');
        $table->foreign('city_id')->references('id')->on('cities')->onDelete('cascade');
    });
}

index.blade.php

<form action="{{ route('send') }}" method="post">
    {{ csrf_field() }}
    <div class="form-group" id="form-group-1">
        <label for="mobile_number">mobile_number</label>
        <input type="text" class="form-control" name="mobile_number" id="mobile_number">
    </div>
    <div class="form-group" id="form-group-2">
        <label for="code">code</label>
        <input type="text" class="form-control" name="code" id="code">
    </div>
    <div class="form-group">
        <button type="submit" class="btn btn-danger" id="btn-ok">ok</button>
    </div>
</form>

web.php

Route::get('/code', 'HomeController@code')->name('code');
Route::post('/send', 'HomeController@send')->name('send');

HomeController.php

public function send(Request $request)
{
    $user = User::findOrFail($request);
    $code = $request->code;
    $mobile = $request->mobile;
    $checkCode =  User::whereCode($code)->first();
    $checkMobile =  User::whereCode($mobile)->first();
    if ($checkCode == $checkMobile) {
        $user(update->verification_code = 1);
        alert()->success('ok', 'it is ok');
    } else {
        alert()->error('bye', 'it isn't ok');
    }
    return redirect()->back();
}
0 likes
7 replies
mozew's avatar
Level 6

I asked How to update call Session ?

devfrey's avatar

@irankhosravi Why are you always being so rude?

We're not here to do your homework. Only to guide you in the right direction. If you're not going to make an effort towards solving your own problem, nobody will.

And what even is this?

$user(update->verification_code = 1);
Snapey's avatar

Session is not even of any use in this case since it is individual to the one user and will also expire if the user does not reply immediately or if they reply with a different device or browser

Why would you do this and not just store it on the user record where you already have the mobile number anyway.

Are you trying to do this as a form of two factor login or registration step?

Please or to participate in this conversation.