PATH:
home
/
cardxfeb
/
public_html
/
app
/
Repositories
/
Editing: featureRepository.php
<?php namespace App\Repositories; use App\Models\Feature; use Spatie\MediaLibrary\MediaCollections\Exceptions\FileDoesNotExist; use Spatie\MediaLibrary\MediaCollections\Exceptions\FileIsTooBig; /** * Class featureRepository */ class featureRepository extends BaseRepository { /** * @var array */ protected $fieldSearchable = [ 'name', 'description', ]; /** * Return searchable fields */ public function getFieldsSearchable(): array { return $this->fieldSearchable; } /** * Configure the Model **/ public function model() { return Feature::class; } /** * @throws FileIsTooBig * @throws FileDoesNotExist */ public function update($input, $id) { $language = $input['language']; // Generate slug if not providd if (empty($input['slug'])) { $count = Feature::where('language', $language)->count(); $input['slug'] = $language . '.features.' . ($count + 1); } $feature = Feature::findOrFail($id); //$feature = Feature::find($id); if($feature){ $feature->update($input); }else{ $feature = Feature::create($input); } if (isset($input['featureImage']) && ! empty($input['featureImage'])) { $feature->clearMediaCollection(Feature::PROFILE); $feature->addMedia($input['featureImage'])->toMediaCollection(Feature::PROFILE, config('app.media_disc')); } return $feature; } }
SAVE
CANCEL