CURRENT PATH:
/
home
/
u451283037
/
domains
/
rupandehiinstitute.com
/
public_html
/
subdomains
/
smarttraining
/
app
/
KEMBALI
|
HOME
Upload File Local:
Upload
Upload via URL:
Download
Dir Baru
File Baru
Editing:
Course.php
<?php namespace App; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Auth; class Course extends Model { protected $guarded = []; public static function getBranchWiseData() { $branchId = Auth::user()->branch_id; $userRole = strtoupper(Auth::user()->roles[0]['name']); if (in_array($userRole, ['SUPER ADMINISTRATOR', 'ADMINISTRATOR'])) { return self::query(); } else { return self::whereBranchId($branchId); } } public function category() { return $this->belongsTo(Category::class); } public function period() { return $this->belongsTo(Period::class); } public function brand() { return $this->belongsTo(Brand::class); } public function branch() { return $this->belongsTo(Branch::class); } public function invoiceItem() { return $this->hasMany(SalesItem::class); } public function filterDataApi() { return [ 'course_id' => $this->id, 'name' => $this->name, 'course_code' => $this->code, 'category_name' => $this->category->name ?? '-', 'price' => $this->price, 'duration' => $this->duration, 'no_of_rounds' => $this->no_of_rounds, 'period' => $this->period->name ?? '-', 'image' => $this->getImage(), ]; } public function getImage() { if (empty($this->image)) { return asset('public/images/logo.png'); } elseif (file_exists('public/' . $this->image)) { return asset('public/' . $this->image); } else { return asset('public/images/logo.png'); } } }
SIMPAN
BATAL