Quiero unir la tabla destinations_travels
(tabla pivote entre travels
y destinations
) con users en otra tabla pivote que sería destinations_travels_users
, mi duda viene a la hora de hacer la relación entre moedelos, ya que cuando hago el belongs to many en usuarios tengo que referirme a un modelo(destinations_travel
) tabla la cual no tiene modelo, ¿creo modelo de la tabla aunque sea tabla pivote? ¿que nombre debería ponerle en ese caso? gracias de antemano
//tabla destinations_travels (es una tabla pivote)
public function up()
{
Schema::create('destinations_travels_users', function (Blueprint $table) {
$table->increments('id');
$table->string('rating');
$table->string('image');
$table->string('start_date');
$table->string('ending_date');
$table->integer('destinations_travel_id')->unsigned()->nullable();
$table->integer('users_id')->unsigned()->nullable();
$table->foreign('destinations_travel_id')->references('id')->on('destinations_travels');
$table->foreign('users_id')->references('id')->on('users');
$table->timestamps();
});
}
//tabla User
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('profile');
$table->string('username');
$table->string('password');
$table->string('email');
$table->rememberToken();
$table->timestamps();
});
}
//tabla destinations_travels_users
public function up()
{
Schema::create('destinations_travels_users', function (Blueprint $table) {
$table->increments('id');
$table->string('rating');
$table->string('image');
$table->string('start_date');
$table->string('ending_date');
$table->integer('destinations_travel_id')->unsigned()->nullable();
$table->integer('users_id')->unsigned()->nullable();
$table->foreign('destinations_travel_id')->references('id')->on('destinations_travels');
$table->foreign('users_id')->references('id')->on('users');
$table->timestamps();
});
}
//Este codigo es en el que me refiero que debería dejar el modelo de users
public function destinations_travels(){
return $this->belongsToMany(::class)
->withPivot('rating','image','start_date','ending_date')->withTimestamps();
}