![]() Server : Apache/2.4.62 (Unix) OpenSSL/1.0.2k-fips System : Linux server1.richineiserver.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : fdshops ( 1003) PHP Version : 8.2.21 Disable Function : NONE Directory : /home/fdshops/public_html/app/ |
<?php namespace App; use DB; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class Unit extends Model { use SoftDeletes; /** * The attributes that should be mutated to dates. * * @var array */ /** * The attributes that aren't mass assignable. * * @var array */ protected $guarded = ['id']; /** * Return list of units for a business * * @param int $business_id * @param bool $show_none = true * @return array */ public static function forDropdown($business_id, $show_none = false, $only_base = true) { $query = Unit::where('business_id', $business_id); if ($only_base) { $query->whereNull('base_unit_id'); } $units = $query->select(DB::raw('CONCAT(actual_name, " (", short_name, ")") as name'), 'id')->get(); $dropdown = $units->pluck('name', 'id'); if ($show_none) { $dropdown->prepend(__('messages.please_select'), ''); } return $dropdown; } public function sub_units() { return $this->hasMany(\App\Unit::class, 'base_unit_id'); } public function base_unit() { return $this->belongsTo(\App\Unit::class, 'base_unit_id'); } }