Open sidebar
//в модели определяешь class ImageOption extends Model { protected $fillable = [ 'image_id', 'name', 'options', ]; protected $casts = [ 'options' => 'array', ]; public function image(): BelongsTo { return $this->belongsTo('App\Image'); } } //валидируешь public function rules() { return [ 'image_id' => 'required|exists:images,id', 'name' => 'required|max:255', 'options' => 'required', ]; } //добавляешь public function store(CreateImageOptionRequest $request): ImageOption { $imageOption = ImageOption::create($request->all()); return $imageOption; } //вызываешь public function option(Image $image, $name): array { $image->load(['options' => function($query) use($name) { $query->where('name', $name); }]); $src = Cloudder::show($image->slug, $image->options->first()->options); return compact('src', 'image'); }
Close sidebar
Back
Please note that all pasted data is publicly available.
Twitter
GitHub
Use setting
Back
Please note that all pasted data is publicly available.
Twitter
GitHub
Use setting