Hi i am new to laravel i am having trouble in inserting data into database and throwing error as
"count(): Parameter must be an array or an object that implements Countable"
i want to add attendence details of all the registred employees in the databse
controller
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');
}
Blade output:
Submit Id First Name Last Name DateOfJoining post Remark @foreach( $data as $row ) {{ $row->id }} {{ $row->first_name }} {{ $row->last_name }} {{ $row->date_joining }} {{ $row->post }}     Present     Absent @endforeach Id First Name Last Name DateOfJoining post RemarkModel class employee_attendence extends Model { //
protected $fillable = array('is_present' ,'date', 'user_id' );
//protected $fillable=[];
public $timemstamps= false ;
public function employee_data(){
//return $this->hasOne(employee_data::class,'App/employee_data');
return $this->hasOne('App\employee_data');
}
}
Model2
namespace App;
use Illuminate\Database\Eloquent\Model;
class employee_data extends Model { //protected $fillabel=['first_name','last_name','contact_no','date_joining','post'];
protected $fillable = array('first_name', 'last_name', 'contact_no' ,'date_joining','post' );
//protected $fillable=[];
public $timemstamps= false ;
public function employee_attendence()
{
//return $this->hasOne( employee_attendence::class, 'App/employee_attendence');
return $this->belongsTo('App\employee_attendence');
}
}

is_presentan array from the view side ? - Akhtar MunirAbsentandPresentSo check the conditions accordingly. - Akhtar Munir