PrintPartImage.php 697 B

12345678910111213141516171819202122232425
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Traits\ModelLogChanging;
  5. use Illuminate\Database\Eloquent\Relations\HasOne;
  6. class PrintPartImage extends Model
  7. {
  8. use ModelLogChanging;
  9. protected $fillable = ['name'];
  10. public function file(): HasOne
  11. {
  12. return $this->hasOne(UploadFile::class,'table_id','id')->where('table_name','print_part_images');
  13. }
  14. public function saveFile($file,$fileName){
  15. $fileSuffix=strtolower($file->getClientOriginalExtension());
  16. return UploadFile::query()->updateOrCreate(['table_name' => $this->getTable(), 'table_id' => $this['id'], 'url' => '/files/'.$fileName, 'type' => $fileSuffix]);
  17. }
  18. }