Laravel many to many relationship error

Nitish Kumar

I'm having two models under the name of Plugins and User with tables respectively. I'm trying to have many to many relationship with a pivot table named plugin_user in the migration named create_users_plugins_table.php.

Following is the schema:

public function up()
{
    Schema::create('plugin_user', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('user_id');
        $table->integer('plugins_id');
        $table->json('contents');
        $table->timestamps();
    });
}

In the User model I've following function for relationship:

public function userplugins(){

    return $this->belongsToMany('App\Plugins')->withPivot('contents');
}

While fetching the row by following code:

$user = User::findorFail($id);
return $user->userplugins()->first()->contents;

I'm getting an following error:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nitsbuilder.plugins_user' doesn't exist (SQL: select plugins.*, plugins_user.user_id as pivot_user_id, plugins_user.plugins_id as pivot_plugins_id, plugins_user.contents as pivot_contents from plugins inner join plugins_user on plugins.id = plugins_user.plugins_id where plugins_user.user_id = 1 limit 1)

Please help me out in fixing this bug.

Thanks

Ariful Haque

Looks like in your Migration, your table name is

`plugin_user` 

but the query searching for

`plugins_user`

You might need to update your Plugin model with the table name.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Laravel save / update many to many relationship

From Dev

Eager loading with many to many relationship in laravel 4

From Dev

Friendship system with Laravel : Many to Many relationship

From Dev

Is this many-to-many relationship possible in Laravel?

From Dev

laravel syncing many-to-many relationship

From Dev

Laravel Polymorphic many to many relationship issue

From Dev

Laravel many to many relationship using Eloquent

From Dev

Laravel Complicated inner join on many to many relationship

From Dev

Advanced search with many to many relationship in laravel

From Dev

Laravel - Many to Many relationship

From Dev

Laravel: one to many relationship

From Dev

Laravel many-to-many relationship on the same model

From Dev

Laravel 5.2 Friendship system: Many to Many relationship

From Dev

How to get many to many relationship items in laravel

From Dev

Laravel 5 Eloquent count many to many relationship

From Dev

Laravel Many to Many query relationship with where clause

From Dev

how to define many to many relationship in laravel models?

From Dev

Laravel 6 many to many relationship

From Dev

Laravel Many to many relationship get specific data

From Dev

Grails many to many relationship error

From Dev

Laravel 4 many to many relationship error when no records match

From Dev

Laravel Many to Many Relationship - Linking 3 items

From Dev

Laravel Removing Pivot data in many to many relationship

From Dev

Pagination with many to many relationship in laravel

From Dev

Laravel many to many relationship with conditions

From Dev

Many to many relationship in Laravel

From Dev

one to many relationship in laravel

From Dev

Many to Many relationship with Laravel

From Dev

Laravel ORM many to many relationship

Related Related

  1. 1

    Laravel save / update many to many relationship

  2. 2

    Eager loading with many to many relationship in laravel 4

  3. 3

    Friendship system with Laravel : Many to Many relationship

  4. 4

    Is this many-to-many relationship possible in Laravel?

  5. 5

    laravel syncing many-to-many relationship

  6. 6

    Laravel Polymorphic many to many relationship issue

  7. 7

    Laravel many to many relationship using Eloquent

  8. 8

    Laravel Complicated inner join on many to many relationship

  9. 9

    Advanced search with many to many relationship in laravel

  10. 10

    Laravel - Many to Many relationship

  11. 11

    Laravel: one to many relationship

  12. 12

    Laravel many-to-many relationship on the same model

  13. 13

    Laravel 5.2 Friendship system: Many to Many relationship

  14. 14

    How to get many to many relationship items in laravel

  15. 15

    Laravel 5 Eloquent count many to many relationship

  16. 16

    Laravel Many to Many query relationship with where clause

  17. 17

    how to define many to many relationship in laravel models?

  18. 18

    Laravel 6 many to many relationship

  19. 19

    Laravel Many to many relationship get specific data

  20. 20

    Grails many to many relationship error

  21. 21

    Laravel 4 many to many relationship error when no records match

  22. 22

    Laravel Many to Many Relationship - Linking 3 items

  23. 23

    Laravel Removing Pivot data in many to many relationship

  24. 24

    Pagination with many to many relationship in laravel

  25. 25

    Laravel many to many relationship with conditions

  26. 26

    Many to many relationship in Laravel

  27. 27

    one to many relationship in laravel

  28. 28

    Many to Many relationship with Laravel

  29. 29

    Laravel ORM many to many relationship

HotTag

Archive