'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'posts.post' doesn't exist

I'm very confused, i try to find what's wrong but i don't find it..

In my SQL Database i've 'posts' table created all my code are related with 'posts' table and not 'post' and im getting this error

Here is my Controller store method:

public function store(CreatePostRequest $request)
{
    //
    Post::create([
        'title'=>$request->title,
        'description'=>$request->descriptions,
        'is_active'=>isset($request->is_active)?1:0
    ]);
    falsh("Post Created Successfully");
    return redirect()->route('post.index');

}

And here is my model:

class posts extends Model
{
    use HasFactory;
    protected $fillable=['title','description','is_active'];
    protected $table = 'post';

}

Here is my artisan migrate table

class CreatePostsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->id();
            $table->string('title',100);
            $table->text('description');
            $table->boolean('is_active')->default(true);
            $table->timestamps();
        });
    }

How can i troubleshoot this?



Solution 1:[1]

  1. Model name is incorrect, not to mention you are calling Post::create and naming the model posts
  2. Spot typos

Also a model with a lowercase letter is bad prac. class Post below is the typo. naming it post while creating a table posts To fix just remove the protected since its called posts regardless. rename your class to class Post done.

    protected $table = 'post';
Schema::create('posts', ....

try to spot typos

Solution 2:[2]

create table for name (posts) not post. name table is (example+s) = posts

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Michael Mano
Solution 2 Djalal Messerhi