Support the ongoing development of Laravel.io →
posted 6 years ago

Hello. Im really sorry for my bad english, but i need help. I create two tables with relation One to many. But when I try to use this code

function createclaim(Request $request){
      $claim = new Claim;
      $claim->title = $request["title"];
      $claim->description = $request["description"];
      $claim->save();

      $files = $request->file;

      foreach ($files as $key => $value) {
        $claimFile = new ClaimFiles;
        $claimFile->urlfile = $value->store('upload');
        $claim->files()->save($claimFile);
      }

      return dd($claim);
    }

I got error and in error message saw another name of table "claim_claimfiles" (name of table is "claimfiles"). BUT then i change table name to "claim_claimfiles" then... I have error and in error message i saw name of table "claimfiles". Can anyone help me to fix it?

if real name of table is "claimfiles"


SQLSTATE[42S02]: Base table or view not found: 1146 Table 'main_bd.claim_claimfiles' doesn't exist (SQL: insert into `claim_claimfiles` (`claim_id`, `claimfiles_id`) values (1, 1))

if real name of table is "claim_claimfiles"


SQLSTATE[42S02]: Base table or view not found: 1146 Table 'main_bd.claimfiles' doesn't exist (SQL: insert into `claimfiles` (`claim_id`, `claimfiles_id`) values (1, 1))
Last updated 2 years ago.
0

it may look a little awkward but it may help to clear your cache and in your model use this line tell your model what table to use

protected $table = "your_table_name";

and double check your table name is the same hope it would help :)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.

© 2025 Laravel.io - All rights reserved.