Edit File: InterestService.php
<?php namespace App\Services\Entity; use App\Models\Interest; class InterestService extends BaseService { /** * Initializes the InterestService class. * * @param Interest $interest The country model instance. */ public function __construct(Interest $interest) { $this->model = $interest; } public function store($request) { $interest = $this->model->create($request->validated()); $this->addOptions($request['options'], $interest); return ['key' => 'success', 'url' => route('admin.interests.index')]; } public function show($id) { $interest = $this->model->with('options')->find($id); return view('admin.interests.show', compact('interest')); } /** * Add options to the interest. * @param $options * @param $interest */ protected function addOptions($options, $interest) { $data = []; foreach ($options as $option) { $data[] = [ 'name' => [ 'ar' => $option['ar'], 'en' => $option['en'], ], ]; } $interest->options()->createMany($data); } }
Back to File Manager