mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-13 17:14:10 -08:00
baa3be728d
* Adds the ability to search by dates Adding extra „where“-conditions to the „TextSearch“ queries, allowing the users to search by dates * Adds missing dates to $dates in models * Removes duplicated „where“ conditions * Adds the Searchable trait to models, defining the searchable attributes and relations * Removes the old text search methods * Adds back additional conditions to the search These conditions could not be modeled in the „attributes“ or „relations“, so we include them here * Removes unnecessary check for the deleted_at attribute * Fixes typo in comments * suppresses errors from Codacy We can safely ignore the error codacy is throwing here, since this method is a standin/noop for models who need to implement more advanced searches
62 lines
1.5 KiB
PHP
Executable file
62 lines
1.5 KiB
PHP
Executable file
<?php
|
|
namespace App\Models;
|
|
|
|
use App\Models\Traits\Searchable;
|
|
use App\Presenters\Presentable;
|
|
use Watson\Validating\ValidatingTrait;
|
|
|
|
class Depreciation extends SnipeModel
|
|
{
|
|
protected $presenter = 'App\Presenters\DepreciationPresenter';
|
|
use Presentable;
|
|
// Declare the rules for the form validation
|
|
protected $rules = array(
|
|
'name' => 'required|min:3|max:255|unique:depreciations,name',
|
|
'months' => 'required|max:3600|integer',
|
|
);
|
|
|
|
/**
|
|
* Whether the model should inject it's identifier to the unique
|
|
* validation rules before attempting validation. If this property
|
|
* is not set in the model it will default to true.
|
|
*
|
|
* @var boolean
|
|
*/
|
|
protected $injectUniqueIdentifier = true;
|
|
use ValidatingTrait;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = ['name','months'];
|
|
|
|
use Searchable;
|
|
|
|
/**
|
|
* The attributes that should be included when searching the model.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $searchableAttributes = ['name', 'months'];
|
|
|
|
/**
|
|
* The relations and their attributes that should be included when searching the model.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $searchableRelations = [];
|
|
|
|
|
|
public function has_models()
|
|
{
|
|
return $this->hasMany('\App\Models\AssetModel', 'depreciation_id')->count();
|
|
}
|
|
|
|
public function has_licenses()
|
|
{
|
|
return $this->hasMany('\App\Models\License', 'depreciation_id')->count();
|
|
}
|
|
}
|