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:
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* [@return](https://ed.team/return) void
*/
public function up(https://)
{
Schema::create(https://'users', function (Blueprint $table) {
$table->id(https://);
$table->string(https://'name');
$table->string(https://'email')->unique(https://);
$table->timestamp(https://'email_verified_at')->nullable(https://);
$table->string(https://'password');
$table->rememberToken(https://);
$table->timestamps(https://);
$table->integer(https://'id_rol')->unsigned(https://);
$table->foreign(https://'id_rol')->references(https://'id')->on(https://'rols');
});
}
}
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
class CreateRolsTable extends Migration
{
/**
* Run the migrations.
*
* [@return](https://ed.team/return) void
*/
public function up(https://)
{
Schema::create(https://'rols', function (Blueprint $table) {
$table->id(https://);
$table->string(https://'name');
$table->timestamps(https://);
});
}
}
Estas es la tabla intermedia donde referencio las tres tablas rol, operaciones y productos
class OperacionesProductoRol extends Migration
{
/**
* Run the migrations.
*
* [@return](https://ed.team/return) void
*/
public function up(https://)
{
//
Schema::create(https://'OperacionesProductoRol', function (Blueprint $table){
$table->id(https://);
$table->integer(https://'id_rol')->unsigned(https://)->nullable(https://);
$table->integer(https://'id_operaciones')->unsigned(https://)->nullable(https://);
$table->integer(https://'id_productos')->unsigned(https://)->nullable(https://);
$table->foreign(https://'id_rol')->references(https://'id')->on(https://'rols');
$table->foreign(https://'id_operaciones')->references(https://'id')->on(https://'operaciones');
$table->foreign(https://'id_productos')->references(https://'id')->on(https://'productos');
});
}
}
Modelo user
public function rol(https://){
return $this->hasOne(https://'App\Rol');
}
```
Rol :
```php
public function user(https://){
return $this->belongsToMany(https://'App\User');
}
public function producto(https://){
return $this->belongsToMany(https://'App\Producto');
}
public function operaciones(https://){
return $this->belongsToMany(https://'App\Operaciones');
}
```
Producto
```php
public function rol(https://){
return $this->belongsToMany(https://'App\Roll');
}
public function operaciones(https://){
return $this->belongsToMany(https://'App\Operaciones');
}
```
Modelo de operaciones
```php
public function producto(https://){
return $this->belongsToMany(https://'App\Producto');
}
public function rol(https://){
return $this->belongsToMany(https://'App\Rol');
}
```