Laravel 4 laravel 4如何实现多态关系存储库
我有摩普托(公共汽车)、摩普托(SUV)和摩普托(轿车)等车辆 在VehicleController中保存时,我调用了vehicleRepository接口,vehicleRepository 如何保存公交车、SUV或轿车数据 我的车辆等级Laravel 4 laravel 4如何实现多态关系存储库,laravel-4,repository-design,Laravel 4,Repository Design,我有摩普托(公共汽车)、摩普托(SUV)和摩普托(轿车)等车辆 在VehicleController中保存时,我调用了vehicleRepository接口,vehicleRepository 如何保存公交车、SUV或轿车数据 我的车辆等级 Class Vehicle controller{ public function get_create(){ if($this->vehicle->create(Input::all())) return
Class Vehicle controller{
public function get_create(){
if($this->vehicle->create(Input::all()))
return Redirect::to()
}
return Redirect::to()->withInput()->withErrors($this->vehicle->getMessages());
}
My Vehicle Repository Class如何处理具有Morpto关系的if(车辆类型为Bus/SUV/Van)
Class VehicleRepository Implements VehicleRepositoryInterface{
public function create($array $inputs){
if($this->validatator->IsValid($inputs)){
// How to implement BUS or SUV or Van in here
$this->model->create($inputs);
return true;
}
return false;
}
}
最后,我得到了保存在存储库中的多态关系的答案 在创建函数中--
非常感谢高级修改或建议,以便更好地处理 最后,我得到了保存在存储库中的多态关系的答案。在create函数中--if($this->validator->isValid($attributes){}
if($this->validator->isValid($inputs){
// first store in temp model. $this model will be destroyed.
$temp_model = $this->model->create($inputs);
//then Depency Injection comein for polymorphic model
$this->polymorphicmodel->create($subinputs):
// link with polymorphic relation
$this->polymorphicmodel->modelable()->save($temp_model);
return true;
}
return false;