Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutator doesn't work well with firstOrCreate #23541

Closed
0xtoorich opened this issue Mar 14, 2018 · 1 comment
Closed

Mutator doesn't work well with firstOrCreate #23541

0xtoorich opened this issue Mar 14, 2018 · 1 comment

Comments

@0xtoorich
Copy link

  • Laravel Version: 5.6.11
  • PHP Version: 7.2.3
  • Database Driver & Version: MySQL 5.7.21

Description:

// ips table migration

Schema::create('ips', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('ip')->unsigned()->index();
});
// Ip model

public function getIpAttribute($value)
{
    return long2ip($value);
}

public function setIpAttribute($value)
{
    $this->attributes['ip'] = ip2long($value);
}
// Controller
Ip::firstOrCreate(['ip' => $request->ip()]);

Steps To Reproduce:

  1. Visit the route many times.
  2. Got duplicate records, the firstOrCreate doesn't work correctly.
@staudenmeir
Copy link
Contributor

#14649

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants