undefined index

Posted 2 months ago by PaulCatalin97

i`m trying to insert some data in model and i get this error

this is my form for this specific column

 <div class="dropdown-field">
                                    <select data-placeholder="Selecteaza Specializare" class="chosen" id="skills" name="skills" multiple="multiple">
                                        @foreach($skills as $skill)
                                            <option value="{{$skill->id}}" >{{strtoupper($skill->name)}}</option>
                                        @endforeach
                                    </select>
                                    <div class="box-footer">

and this is the controller

 class AdaugaJobController extends Controller
{

    public function __construct()
    {
        $this->middleware('auth');
    }

    public function index()
    {
        $skills = SkillsEmployee::all();
        return view('adaugajob', compact('skills'));
    }

    public function store(Request $request)
    {
        $data = $request->validate([
            'titlu' => 'required|string|max:255',
            'descriere' => 'required|string|max:255',
            'salariu_estimativ' => 'required|string|max:255',
            'oras'=> 'required',
            'id_skill'=>'',

        ]);

        $skills = $data['skills[]'];

        foreach($skills as $skill){
            Joburi::create([
                'titlu' => $data['titlu'],
                'descriere' => $data['descriere'],
                'salariu_estimativ' => $data['salariu_estimativ'],
                'oras' => $data['oras'],
                'id_skill'=>$skill,
            ]);
        }
        if($data){
            return redirect()->route('adaugajob')->withSuccess('S-a incarcat cu success!');
        }else{
            return redirect()->route('adaugajob')->withDanger('Nu s-a incarcat! A aparut o eroare.');
        }
        }
    }

Please sign in or create an account to participate in this conversation.