Support the ongoing development of Laravel.io →
Database Eloquent

I get following error:

Illuminate \ Database \ QueryException (42S02) 
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'l4orm.posts' doesn't exist (SQL: insert into `posts` (`title`, `body`) values (post, body for the post))

Database l4.orm table:

  • authors
  • migrations
  • post.

model Authors

class Authors extends \Eloquent {
	
	public function post()
	{
		return $this->hasMany('Post');
	}
}

Routes

Route::get('/', function()
{
	Authors::find(1)->post()->insert(array(
		'title'=>'post',
		'body' =>'body for the post'));
});

Last updated 3 years ago.
0

The error is pretty self explanatory. It's trying to insert into a table called "posts" that doesn't exist.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

scarings scarings Joined 26 Jul 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.

© 2025 Laravel.io - All rights reserved.