【发布时间】:2016-07-13 14:27:38
【问题描述】:
谢谢大家,我有两张表,一张名为 Produto,另一张名为 ProdutoCategoria。当我建立模型的关系时,只有 ProdutoCategoria 对象返回了 Produdo,而 Produto 没有返回对象 ProdutoCategoria,为什么?
class ProdutoCateg extends Model
{
public function produtos(){
return $this->hasMany('app\Produto');
}
}
class Produto extends Model
{
public function categoria(){
return $this->belongsTo('app\ProdutoCateg');
}
}
class Fktables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('produtos', function ($table){
$table->foreign('id_produto_categs')->references('id')->on('produto_categs');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
【问题讨论】:
-
Produto 返回什么?
-
你能告诉我们你的迁移吗?不仅是外键创建
标签: laravel laravel-5 eloquent