Laravel 5.7: Why do my model create() and save() methods create 2 records when called?

Laravel 5.7: Why do my model create() and save() methods create 2 records when called?

I am using mysql DB, Laravel 5.7, on Apache.

I am using mysql DB, Laravel 5.7, on Apache.

I already have a full system running, and all seems to be fine, except...I decided to start using some eloquent factories for testing, and noticed that the factories were making 2 entries in mysql when I save/create a model. So I simplified, and created my own "makeFake" method, and find that its doing the same thing. I don't know what I have done wrong. Or maybe there is some area of the framework that I do not fully understand.

Main question: Why do my model create() and save() methods create 2 records when called?

Simplified case below... (in this case, I am calling 2 methods to create a company, but I am getting 4 company records)

From my web.php

Route::get('/savingTest', function () {

$company = App\Company::makeFake1();
dump($company);

$company = App\Company::makeFake2();
dump($company);

return 'complete';

});

From my Company.php model (I already loaded faker and GUID libraries)

public static function makeFake1()
{
    $faker = Faker::create();
    $company = new Company;
    $company->code = $faker->word;
    $company->name = $faker->company;
    $company->guid = Guid::create();
    $company->save();
    return $company;
}

public static function makeFake2() { $faker = Faker::create(); return Company::create([ 'code' => $faker->word, 'name' => $faker->company, 'guid' => Guid::create(), ]);

}


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

PHP Interview Questions with Solutions: Prepare for PHP Interview

Prepare for PHP Interviews. Set Variable With php.ini File. Logic & Output Behind PHP Code Segment. Class Concept, Error & Functions in PHP. Start PHP Now!

PHP Web Application Development Company

As a top **PHP Web Application Development Company in USA**[https://www.dataeximit.com/php-development-services/](https://www.dataeximit.com/php-development-services/ "https://www.dataeximit.com/php-development-services/"), we at Data EximIT have...

Advantages of Hiring PHP Developer for your Website Project

PHP - Hypertext pre-processor, a scripting language used by many people in developing web pages, but most of us are unaware even of the full form. To train someone and make them learn this whole language is as difficult and time-consuming as it is...