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(), ]);

}


php

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire PHP Developer

Looking to develop a PHP based website from scratch or revamp your existing website? **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")** has always been an industry leader for companies and business owners looking to hire...

Hire Dedicated PHP Developer

Looking to hire affordable yet experienced PHP developers? **[Hire Dedicated PHP Developer](https://hourlydeveloper.io/hire-dedicated-php-developer/ "Hire Dedicated PHP Developer")**, who can convert your idea to reality, within the stipulated...

Country State City Dropdown list in PHP MySQL PHP

Country state city dropdown using ajax in php. You'll learn how to populate country city state dropdown based on previous selection in php using ajax

PHP json_decode Example | Decode JSON Data in PHP Tutorial

PHP json_decode is an inbuilt function that takes the JSON encoded string and converts it into a PHP variable. JSON stands for JavaScript Object Notation.

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...