Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Aronaman's avatar

Call to a member function 'method'() on null

error


   Symfony\Component\Debug\Exception\FatalThrowableError  : Call to a member function localpayment() on null

  at C:\laragon\www\Getrest\database\seeds\CreateAdminUserSeeder.php:40
    36|         $local_payment=App\LocalPayment::find(1);
    37|         $local_reservation=App\LocalReservation::find(1);
    38|
    39|       $local_payment=factory(App\LocalPayment::class,10)->make();
  > 40|        $local_book->localpayment()->save($local_payment);
    41|
    42|         $refund=factory(App\Refund::class,100)->make();
    43|
    44|        $local_payment->refunds()->saveMany($refund);

  Exception trace:


//** local payment 
       //one to one
        // App\LocalPayment::truncate();
        $local_book=App\LocalBook::find(1);
        $local_payment=App\LocalPayment::find(1);
        $local_reservation=App\LocalReservation::find(1);

      $local_payment=factory(App\LocalPayment::class,10)->make();
       $local_book->localpayment()->save($local_payment); 

        $refund=factory(App\Refund::class,100)->make();
      
       $local_payment->refunds()->saveMany($refund);

       $localhistory=factory(App\LocalHistory::class,100)->make();
      
       $local_payment->localHistories()->saveMany( $localhistory);

      
//1 to many localpayment->bookstatus
        $bookstatus=factory(App\BookStatus::class, 20)->make();
       $local_payment->bookstatus()->saveMany($bookstatus);
//1 to many localpayment->checkandbalance
       $checkbalance=factory(App\CheckandBalance::class,20)->make();
       $local_payment->checkbalance()->saveMany($checkbalance);

//***local reservation 
       $localbook=factory(App\LocalReservation::class,10)->make();
       $local_reservation->localBooks()->saveMany( $localbook);

localBook MODEL


 public function localpayment(){
      
       return  $this->hasOne(LocalPayment::class);


        }
0 likes
3 replies
Sinnbeck's avatar

Just as the error says $local_book is null. This happens when nothing is found in the database

$local_book=App\LocalBook::find(1);
Aronaman's avatar

i try to seed data using faker !

 //pivot table LocalbookConfrencetype 
       factory(App\LocalBook::class,50)->create();
Sinnbeck's avatar

And you do this before the pasted code?

1 like

Please or to participate in this conversation.