laravel中将多个数据插入数据库

嗨,我是laravel的新手,我无法将数据插入数据库并抛出错误

“ count():参数必须为        数组或实现Countable的对象”

我想在数据库中添加所有注册员工的出勤详细信息

控制者

    public function Attendence() 
    {
        $data=employee_data::all();
        return view('attendence',compact('data'));
    }   

    public function mark_attendence(Request $request)
    {
        $request->validate([
        'date'  =>  'required',
        'is_present'  =>  'required'

        ]);


        $data=$request->all();
        $last_id=employee_data::create($data)->id;
        if (count($request->is_present) >0 )
         {
            # code...
            foreach ($return->is_present as $item => $v)
            {
                $data2=array(
                    'is_present' =>$request->is_present[$item],
                    'date'=> $request->date[$item],
                    'user_id'=>$last_id
                );

            }
        //$data2->save();

    //$employee->save();
    //$employee->employee_data()->create([]);



        return redirect('/index')->with('succ','Attendence Added Successfully');
    }

刀片输出:

enter image description here

评论