sajioljpo

sajioljpo

Member Since 4 Months Ago

Experience Points
130
Total
Experience

4,870 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
130 XP
Aug
12
4 months ago
Activity icon

Replied to Race Conditions On User Registration

@snapey As I said in the first post, using firstOrCreate also doesn't solve the problem.

Aug
11
4 months ago
Activity icon

Replied to Race Conditions On User Registration

As far as I know, programming languages must use algorithms like Semaphore to prevent race condition. Now I don't know how php does it.

Anyone have any information about locking tables or using transactions? How does it work and how does using these methods affect the performance of the rest of the program?

I want to solve this problem without changing the structure of the tables, through coding.

Activity icon

Replied to Race Conditions On User Registration

@snapey I don't think Front-end changes can solve this problem, but I'll try.

I can't change the structure of the tables. Because it causes Data Redundancy. Changing information also causes problems when reusing it.

Aug
09
4 months ago
Activity icon

Replied to Race Conditions On User Registration

@jlrdw

The phone number may not be unique on many sites but on my site it is unique and no one shares their number with another. I'm sure of that.

If I want to save information to another table, there is a redundancy of information. Several other tables are associated with the User table.

Activity icon

Replied to Race Conditions On User Registration

@snapey

If a user deletes their account, they can sign up again with their previous phone number.

I cannot change or delete information. I need to keep my user registration records.

I looked at the users' table and found records repeated. All information is the same even created_at and updated_at. It is only possible to repeat the data once the user has deleted and re-registered his account, but two consecutive duplicate records mean race condition. I think this is due to the slow speed of internet users.

Probably two queries at a time pass the validation done in Laravel and the duplicate record is created because there is no unique field in the table.

Activity icon

Replied to Race Conditions On User Registration

@jlrdw

Because I used deleted_at in the table. So the phone field should be unique unless the previous records have a value in deleted_at.

Activity icon

Replied to Race Conditions On User Registration

@click I didn't know it was possible!

So I make the phone + deleted_at fields unique.

Question: Will a user who has already registered with a phone number be prevented from re-registering? Can he re-register if he deletes his account?

If it does, my problem will be solved

Activity icon

Replied to Race Conditions On User Registration

The phone column is unique but not in all cases.

The SoftDelete feature is used in the User model. So when a user deletes their account, a record is not deleted from the table.

also if the user wants to sign up again with the same number, he can do so.

So in this table it is not possible to use a unique field.

Activity icon

Started a new Conversation Race Conditions On User Registration

My app's user table cannot use a unique column. So I've done this with the Laravel validation. The problem with this is that the "race condition" problem sometimes occurs when registering a user.

I have tried several ways to fix the problem

I used firstOrCreate and now firstOrNew but the problem didn't fix.

Although I have checked the record for non-duplicate records in the previous lines, I also checked the record's duplication status when adding records to the database, but the problem was not fixed.

<?php
class RegisterController extends Controller
{
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'phone' => ['required', 'digits:11', 'unique:users,phone,null,id,deleted_at,NULL', phoneRegExValidateRule()],
            // other fields ...
        ]);
    }

    protected function create(array $data)
    {
        $user = User::firstOrNew([
            'phone' => $data['phone'],
        ]);

        if ($user->exists) {
            flash()->error('error', 'duplicate user');

            return redirect()->route('home');
        } else {
            $user->fill([
                // fields ...
            ]);

            $user->save();
        }



        $user->meta()->create([
            // fields ...
        ]);

        return $user;
    }
}

Since the "race condition" problem occurs at the last moment and when the record is inserted into the database, it seems that I should use table locking. But I don't know what happens to other parts of the program that use this table when locked. I also don't know how to write this code