Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

I don't know if it will fix your problem but you don't need the parenthesis after Game.

$game = new Game
Last updated 1 year ago.
0

thank you @eriktisme, but that doesn't work.

Last updated 1 year ago.
0

I'm not sure if it will give you the answers you need but if you throw http://laravel.io/bin/zwW4r into your routes file you should be able to see what is being sent to your DB. I would start there to make sure the sql you intend is being sent. If it is then I would try var_dump-ing the game object before saving. If that doesn't solve it let us know, I'll do some testing to help if I can.

Last updated 1 year ago.
0

The code you have doesn't insert anything twice, so there are 2 things I can think of:

  1. You visit the page twice for some reason
  2. You have an event listener registered that inserts the same thing for the 2nd time under the hood - for example for such events: Game::saving or Game ::saved event
Last updated 1 year ago.
0

Hi kulkarp,

Did you define the app/config/database.php file?

Did you create the database and the migrations for it?

Last updated 1 year ago.
0

@jarektkaczyk Thank you the response.

Even I thought the same thing - visiting page twice, but I am sure that isn't the case. No, I am not even sure how to define event listener in php/laravel, so no I haven't done anything like that.

Last updated 1 year ago.
0

Hi kulkarp,

Did you define the app/config/database.php file?

Did you create the database and the migrations for it?

@codeATbusiness yes, I have defined database.php. I created the database manually, but the single table and alterations to it using migrations.

Last updated 1 year ago.
0

try to use a diferrent path

    Route::get('/add', function(){
       $game = new Game();
       $game->name = 'Assasins Creed';
       $game->description = "Assasins Vs Templars";
       $game->save();
    }); 

does it still add it two times?

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

kulkarp kulkarp Joined 13 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.