16 'name' =>
'required|min:3|max:255|unique:locations,name,NULL,deleted_at',
17 'city' =>
'min:3|max:255',
18 'state' =>
'min:2|max:32',
19 'country' =>
'min:2|max:2|max:2',
20 'address' =>
'min:5|max:80',
21 'address2' =>
'min:2|max:80',
22 'zip' =>
'min:3|max:10',
45 return $this->hasMany(
'\App\Models\User',
'location_id');
50 return $this->hasManyThrough(
'\App\Models\Asset',
'\App\Models\Actionlog',
'location_id',
'id');
55 return $this->hasMany(
'\App\Models\Asset',
'rtd_location_id');
60 return $this->belongsTo(
'\App\Models\Location',
'parent_id');
65 return $this->hasMany(
'\App\Models\Location',
'parent_id');
74 foreach ($locations as $location) {
76 if ($location[
'parent_id'] == $parent_id) {
77 $op[$location[
'id']] =
79 'name' => $location[
'name'],
80 'parent_id' => $location[
'parent_id']
86 $op[$location[
'id']][
'children'] = $children;
98 $location_options = array();
99 foreach ($location_options_array as $id => $value) {
102 $location_options[$id] = $value[
'name'];
105 if (array_key_exists(
'children', $value)) {
107 foreach ($value[
'children'] as $child_id => $child_location_array) {
110 foreach ($child_location_options as $child_id => $child_name) {
111 $location_options[$child_id] =
'--'.$child_name;
119 return $location_options;
133 return $query->where(
'name',
'LIKE',
"%$search%")
134 ->orWhere(
'address',
'LIKE',
"%$search%")
135 ->orWhere(
'city',
'LIKE',
"%$search%")
136 ->orWhere(
'state',
'LIKE',
"%$search%")
137 ->orWhere(
'zip',
'LIKE',
"%$search%")
140 ->orWhere(
function ($query) use ($search) {
141 $query->whereHas(
'parent',
function ($query) use ($search) {
142 $query->where(
function ($query) use ($search) {
143 $query->where(
'name',
'LIKE',
'%'.$search.
'%');
147 ->orWhere(
function ($query) use ($search) {
148 $query->whereRaw(
"parent_id IN (select id from locations where name LIKE '%".$search.
"%') ");
166 return $query->leftJoin(
'locations as parent_loc',
'locations.parent_id',
'=',
'parent_loc.id')->orderBy(
'parent_loc.name', $order);
scopeTextsearch($query, $search)
Query builder scope to search on text.
static getLocationHierarchy($locations, $parent_id=null)
static flattenLocationsArray($location_options_array=null)
scopeOrderParent($query, $order)
Query builder scope to order on parent.