Laravel 4 viele zu viele Beziehung nicht funktioniert, Pivot-Tabelle nicht gefunden
Ich habe derzeit Probleme mit einer n: n-Beziehung mit Laravel 4, ich habe einen Fehler mit Pivot-Tabelle, die auf einer Tabelle mit beiden Komponenten auf Singular Name abfragt. Ich erstelle eine Pivot-Tabelle lands_objs und fülle sie auf:
Modelle sind:
<?php
class Obj extends Eloquent
{
protected $guarded = array();
public static $rules = array();
public $timestamps = false;
public function land()
{
return $this->belongsToMany('Land');
}
<?php
class Land extends Eloquent
{
protected $guarded = array();
public static $rules = array();
public $timestamps = false;
public function objs()
{
return $this->belongsToMany('Obj');
}
}
So fülle ich die Pivot-Tabelle gemäß den Standards aus. Natürlich gibt es die Tabellen lands, objs und lands_objs:
<?php
use Illuminate\Database\Migrations\Migration;
class CreateLandsObjsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('lands_objs', function($table) {
$table->integer('land_id');
$table->integer('obj_id');
});
}
}
Mit dieser Struktur sollte ich dank Eloquent in der Lage sein:
$land = Land::find(1); //checked loads land fine
$objs = $land->objs; //--> HERE I TAKE THE ERROR
Aber ich nehme den Fehler:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'taylor.land_obj' doesn't exist
(SQL: select `objs`.*, `land_obj`.`land_id` as `pivot_land_id`, `land_obj`.`obj_id`
as `pivot_obj_id` from `objs` inner join `land_obj` on `objs`.`id` = `land_obj`.`obj_id`
where `land_obj`.`land_id` = ?) (Bindings: array ( 0 => 1, ))
Sollte Laravel nicht die Tabelle lands_objs erstellen, obwohl er nach land_obj fragt? Vermisse ich etwas?
Danke vielmals.