Mysql Laravel 4和具有多个表的雄辩查询(带)
我是拉威尔发展公司的新员工, 我有代码问题 我有这样的MotorsController.php 我有如下模型 Motor.phpMysql Laravel 4和具有多个表的雄辩查询(带),mysql,laravel,laravel-4,eloquent,Mysql,Laravel,Laravel 4,Eloquent,我是拉威尔发展公司的新员工, 我有代码问题 我有这样的MotorsController.php 我有如下模型 Motor.php <?php class Motor extends Eloquent { protected $table = 'motors'; protected $guarded = array(); public function motorcategory(){ return $this->belongsTo('MotorCategory');
<?php
class Motor extends Eloquent {
protected $table = 'motors';
protected $guarded = array();
public function motorcategory(){
return $this->belongsTo('MotorCategory');
}
public function motorcolor(){
return $this->belongsTo('MotorColor');
}
public static $rules = array(
'name' => 'required',
'police_number' => 'required',
'sex' => 'required'
);
}
在motors.index中,我想获得与表motor_分类和motor_颜色相关的电机数据
但现在我仍然有这样的错误:
BadMethodCallException
Call to undefined method Illuminate\Database\Query\Builder::motor_category()
我希望有人能帮助我。。
顺便说一句,对不起我的英语:
我的汽车指数
<tbody>
@foreach ($motors as $motor)
<tr>
<td>{{ $motors->name }}</td>
<td>{{ $motors->police_number }}</td>
<td>{{ $motors->motor_category->name }}</td>
<td>{{ $motors->motor_color->name }}</td>
<!-- {{{ $categories= Category::find($member->id)}}} -->
<td>{{ $motors->purchace_date}}</td>
<td>{{ $motors->status }}</td>
<td>
{{ link_to_route('motors.show', 'Detail', array($motor->id), array('role' =>'btn', 'class' => 'btn btn-primary btn-xs')) }} |
{{ link_to_route('motors.edit', 'Edit', array($motor->id), array('role' =>'btn', 'class' => 'btn btn-info btn-xs')) }} |
<!-- {{ link_to_route('members.destroy', 'Delete', array($member->id), array('role' =>'btn', 'class' => 'btn btn-danger btn-xs')) }} -->
<!-- </td>
<td> -->
{{ Form::open(array('method' => 'DELETE', 'route' => array('motors.destroy', $motor->id), 'style'=>'display:inline;' )) }}
{{ Form::submit('Delete', array('class' => 'btn btn-danger btn-xs ')) }}
{{ Form::close() }}
</td>
</tr>
@endforeach
</tbody>
motors.index中的代码是什么?我已经准备好编辑这篇文章以添加motors.index删除下划线。使用“motorcategory”、“motorcolor”感谢Marweln。。现在是工作时间。。
class MotorColor extends Eloquent {
//protected $fillable = array('name','semua fieldnya kah ? ','cateogory_id');
public function motor(){
return $this->hasMany('Motor');
}
}
BadMethodCallException
Call to undefined method Illuminate\Database\Query\Builder::motor_category()
<tbody>
@foreach ($motors as $motor)
<tr>
<td>{{ $motors->name }}</td>
<td>{{ $motors->police_number }}</td>
<td>{{ $motors->motor_category->name }}</td>
<td>{{ $motors->motor_color->name }}</td>
<!-- {{{ $categories= Category::find($member->id)}}} -->
<td>{{ $motors->purchace_date}}</td>
<td>{{ $motors->status }}</td>
<td>
{{ link_to_route('motors.show', 'Detail', array($motor->id), array('role' =>'btn', 'class' => 'btn btn-primary btn-xs')) }} |
{{ link_to_route('motors.edit', 'Edit', array($motor->id), array('role' =>'btn', 'class' => 'btn btn-info btn-xs')) }} |
<!-- {{ link_to_route('members.destroy', 'Delete', array($member->id), array('role' =>'btn', 'class' => 'btn btn-danger btn-xs')) }} -->
<!-- </td>
<td> -->
{{ Form::open(array('method' => 'DELETE', 'route' => array('motors.destroy', $motor->id), 'style'=>'display:inline;' )) }}
{{ Form::submit('Delete', array('class' => 'btn btn-danger btn-xs ')) }}
{{ Form::close() }}
</td>
</tr>
@endforeach
</tbody>