Isaac Santaella@isaacsantaella75356

Buenas estoy tratando de hacer relaciones de muchos de muchos a uno y muchos a muchos pero me sale codigo error 150 les muestro las tablas y los modelos

tabla user:

1class CreateUsersTable extends Migration 2{ 3 /** 4 * Run the migrations. 5 * 6 * [@return](https://ed.team/return) void 7 */ 8 public function up(https://) 9 { 10 Schema::create(https://'users', function (Blueprint $table) { 11 $table->id(https://); 12 $table->string(https://'name'); 13 $table->string(https://'email')->unique(https://); 14 $table->timestamp(https://'email_verified_at')->nullable(https://); 15 $table->string(https://'password'); 16 $table->rememberToken(https://); 17 $table->timestamps(https://); 18 $table->integer(https://'id_rol')->unsigned(https://); 19 $table->foreign(https://'id_rol')->references(https://'id')->on(https://'rols'); 20 }); 21 } 22}

Tabla rols, producto y operaciones son los mismos campos pero con diferente nombre. asi que emito sus tablas oslo colocare una para visualizar las tabla

1class CreateRolsTable extends Migration 2{ 3 /** 4 * Run the migrations. 5 * 6 * [@return](https://ed.team/return) void 7 */ 8 public function up(https://) 9 { 10 Schema::create(https://'rols', function (Blueprint $table) { 11 $table->id(https://); 12 $table->string(https://'name'); 13 $table->timestamps(https://); 14 }); 15 } 16}

Estas es la tabla intermedia donde referencio las tres tablas rol, operaciones y productos

1class OperacionesProductoRol extends Migration 2{ 3 /** 4 * Run the migrations. 5 * 6 * [@return](https://ed.team/return) void 7 */ 8 public function up(https://) 9 { 10 // 11 Schema::create(https://'OperacionesProductoRol', function (Blueprint $table){ 12 $table->id(https://); 13 $table->integer(https://'id_rol')->unsigned(https://)->nullable(https://); 14 $table->integer(https://'id_operaciones')->unsigned(https://)->nullable(https://); 15 $table->integer(https://'id_productos')->unsigned(https://)->nullable(https://); 16 $table->foreign(https://'id_rol')->references(https://'id')->on(https://'rols'); 17 $table->foreign(https://'id_operaciones')->references(https://'id')->on(https://'operaciones'); 18 $table->foreign(https://'id_productos')->references(https://'id')->on(https://'productos'); 19 }); 20 } 21}

Modelo user

public function rol(https://){
        return $this->hasOne(https://'App\Rol');
    }

Rol :

1 public function user(https://){ 2 return $this->belongsToMany(https://'App\User'); 3 } 4 public function producto(https://){ 5 return $this->belongsToMany(https://'App\Producto'); 6 } 7 8 public function operaciones(https://){ 9 return $this->belongsToMany(https://'App\Operaciones'); 10 }

Producto

1public function rol(https://){ 2 return $this->belongsToMany(https://'App\Roll'); 3 } 4 5 public function operaciones(https://){ 6 return $this->belongsToMany(https://'App\Operaciones'); 7 }

Modelo de operaciones

1public function producto(https://){ 2 return $this->belongsToMany(https://'App\Producto'); 3 } 4 5 public function rol(https://){ 6 return $this->belongsToMany(https://'App\Rol'); 7 }

Escribe una respuesta