mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 06:57:32 -04:00 
			
		
		
		
	
		
			
				
	
	
		
			31 lines
		
	
	
		
			696 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			696 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?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;
 | |
|         }
 | |
|         
 | |
|         $paramName = $this->entityType . 's';
 | |
|         $publicId = $this->$paramName ?: (Input::get('public_id') ?: Input::get('id'));
 | |
|         
 | |
|         if ( ! $publicId) {
 | |
|             return null;
 | |
|         } 
 | |
|         
 | |
|         $class = Utils::getEntityClass($this->entityType);
 | |
|         $this->entity = $class::scope($publicId)->withTrashed()->firstOrFail();
 | |
|         
 | |
|         return $this->entity;
 | |
|     }
 | |
| }
 |