錯誤消息:http://puu.sh/d4l0F/5b0ac07e68.png調用一個成員函數助理()在非對象
我甚至試圖建立關聯之前,節省了$運輸對象。我已經驗證了$ transporation,$ from和$ to都是它們各自的對象,它們是。
我確定我在這裏錯過了一些愚蠢的東西,但我沒有想法。
我的代碼:
class RideBuilder implements RideBuilderInterface
{
public function create(Advance $advance)
{
$ride = new Ride;
if($ride->validate(Input::all())) {
$ride->save();
$to = Location::find(Input::get('dropoffLocation'));
$from = Location::find(Input::get('pickupLocation'));
$transportation = new Transportation;
$transportation->save();
$transportation->transportable()->associate($ride);
$transportation->to()->associate($to);
$transportation->from()->associate($from);
$event = new Event;
$event->start = Input::get('ridePickUpTime');
$event->save();
$event->eventable->save($transportation);
$event->subjectable->save($advance);
}
return $ride;
}
}
選址模型:
class Location extends Elegant
{
protected $table = 'locations';
public $rules = array(
'label' => 'required|min:2',
'street' => 'required',
'city' => 'required',
'state' => 'required',
'type' => 'required',
);
public function advance()
{
return $this->belongsTo('Booksmart\Booking\Advance\Model\Advance');
}
public function locationable()
{
return $this->morphTo();
}
}
運輸型號:
class Transportation extends Elegant
{
protected $table = 'transportations';
public function event()
{
$this->morphOne('Booksmart\Component\Event\Model\Event');
}
public function start_location()
{
$this->belongsTo('Booksmart\Component\Location\Model\Location', 'start_location');
}
public function end_location()
{
$this->belongsTo('Booksmart\Component\Location\Model\Location', 'end_location');
}
}
您是否在'Transportation'模型上實現了belongsTo'transportable'關係? – 2014-11-25 00:56:51
@SteveBauman'moprhTo'而不是'belongsTo',但是,那肯定是問題所在。 – 2014-11-25 10:10:02
啊,必須這樣!一旦我可以測試,我會作出回答。謝謝。 – 2014-11-25 14:14:20