2016-04-28 14:16:33 +02:00
|
|
|
<?php namespace App\Http\Requests;
|
|
|
|
|
|
|
|
use App\Http\Requests\Request;
|
|
|
|
use Input;
|
|
|
|
use Utils;
|
|
|
|
|
|
|
|
class BaseRequest extends Request {
|
|
|
|
|
|
|
|
protected $entityType;
|
|
|
|
private $entity;
|
|
|
|
|
|
|
|
public function entity()
|
|
|
|
{
|
|
|
|
if ($this->entity) {
|
|
|
|
return $this->entity;
|
|
|
|
}
|
|
|
|
|
2016-04-28 14:20:34 +02:00
|
|
|
$paramName = $this->entityType . 's';
|
|
|
|
$publicId = $this->$paramName ?: (Input::get('public_id') ?: Input::get('id'));
|
2016-04-28 14:16:33 +02:00
|
|
|
|
|
|
|
if ( ! $publicId) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$class = Utils::getEntityClass($this->entityType);
|
|
|
|
$this->entity = $class::scope($publicId)->withTrashed()->firstOrFail();
|
|
|
|
|
|
|
|
return $this->entity;
|
|
|
|
}
|
|
|
|
}
|