| 12345678910111213141516171819202122232425 |
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- use App\Traits\ModelLogChanging;
- use Illuminate\Database\Eloquent\Relations\HasOne;
- class PrintPartImage extends Model
- {
- use ModelLogChanging;
- protected $fillable = ['name'];
- public function file(): HasOne
- {
- return $this->hasOne(UploadFile::class,'table_id','id')->where('table_name','print_part_images');
- }
- public function saveFile($file,$fileName){
- $fileSuffix=strtolower($file->getClientOriginalExtension());
- return UploadFile::query()->updateOrCreate(['table_name' => $this->getTable(), 'table_id' => $this['id'], 'url' => '/files/'.$fileName, 'type' => $fileSuffix]);
- }
- }
|