示例#1
0
function requireMorphInstance($type, $id, $message = null)
{
    $instance = getMorphInstance($type, $id);
    if (!$instance) {
        throw new App\Core\Exceptions\InvalidDataException($message);
    }
    return $instance;
}
示例#2
0
 public function validateMorph($name)
 {
     $morph_type = $this->input($name . '_type');
     $morph_id = $this->input($name . '_id');
     if (!$morph_id or !$morph_type) {
         throw new InvalidDataException();
     }
     $instance = getMorphInstance($morph_type, $morph_id);
     if (is_null($instance)) {
         throw new InvalidDataException();
     }
     return $instance;
 }