2
나는 차량 클래스 morphTo (버스)와 MorphTo (SUV)와 MorphTo (세단)를 가지고있다.laravel 4 다형성 관계 저장소를 구현하는 방법
VehicleController에 저장할 때 vehicleRepositoryInterface, vehicleRepository를 호출했습니다.
버스 나 SUV 또는 세단 데이터를 어떻게 저장할 수 있습니까?
내 차량 클래스 morphTo 관계로 (차량 종류가 버스/SUV/밴 인) 경우 처리하는 방법
Class Vehicle controller{
public function get_create(){
if($this->vehicle->create(Input::all()))
return Redirect::to()
}
return Redirect::to()->withInput()->withErrors($this->vehicle->getMessages());
}
내 차량 저장소 클래스?
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;
}
}
마지막으로 저장소에 저장하기 위해 다형성 관계에 대한 답을 얻었습니다. 작성 함수에서 if ($ this-> validator-> isValid ($ attributes) {} –