Php laravel 4有一个/多个/属于不';行不通
我有一些属于活动模型的模型 在我的Activity.php中Php laravel 4有一个/多个/属于不';行不通,php,laravel-4,Php,Laravel 4,我有一些属于活动模型的模型 在我的Activity.php中 <?php class Activity extends \Eloquent { protected $fillable = []; public function activity_car_nums() { return $this->hasMany('ActivityCarNum'); } public function newables()
<?php
class Activity extends \Eloquent {
protected $fillable = [];
public function activity_car_nums()
{
return $this->hasMany('ActivityCarNum');
}
public function newables()
{
return $this->hasMany('Newable');
}
public function serial_codes()
{
return $this->hasMany('SerialCode');
}
public function applys()
{
return $this->hasMany('Apply');
}
}
因为我真的不知道为什么
谁能帮帮我吗?对不起,我的英语很差。非常感谢。
(如果您需要其他代码,请告诉我。)我的型号代码:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use DB;
class Product extends Model
{
public $table="s_products";
protected $primaryKey = 'product_id';
public function reviews()
{
return $this->hasMany('App\ProductReview');
}
public function attributes()
{
return $this->hasMany('App\AttributeMapping');
}
public function images()
{
return $this->hasMany('App\Image');
}
}
我找到了我的模型查询无法工作的原因,因为函数名中的“\ux”
换衣服
public function serial_codes()
到
然后一切都会好起来的
谢谢大家。我还有另外两个模型,它们与hasOne关联,属于relationship,即使里面有数据,我也无法通过orm查询得到任何东西。你能发布SerialCode和活动模型吗?@Laerte我更新了我的问题:)你用来链接活动和SerialCode的键是什么?我在SerialCode模型中有活动id,像这样$table->integer('Activity_id')->unsigned();$table->foreign('activity_id')->references('id')->on('activities')
我是否应该通过添加名称空间应用程序来更改所有模型;使用Illumb\Database\Elount\Model;使用数据库;类MyModel扩展了模型
???在我像那样更改了所有模型之后,我得到了类“Activity”,但没有找到它,因为$activities=Activity::latest()->get()代码>@hubuki im使用transfromerin,transfromer i使用图像()
//this can get activity object
$activity = Activity::find($id);
//this can get the serial codes of the object above.
$serial_codes = SerialCode::whereActivityId($id)->get();
//this don't work, it returns null
$serial_codes = $activity->serial_codes;
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use DB;
class Product extends Model
{
public $table="s_products";
protected $primaryKey = 'product_id';
public function reviews()
{
return $this->hasMany('App\ProductReview');
}
public function attributes()
{
return $this->hasMany('App\AttributeMapping');
}
public function images()
{
return $this->hasMany('App\Image');
}
}
public function serial_codes()
public function serialcodes()