Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bader_mattar9's avatar

Error when show data and refresh the page using laravel

when i get data from database and get dates from course_dates table show data and sometime show empty

^ Illuminate\Database\Eloquent\Collection {#1445 ▼ #items: [] } when I do refresh to the page show data in laravel

$allCourses = VCourse::with('getDate')->get();

class courseDate extends Model {

protected $table = 'course_dates';
const CREATED_AT = 'dt_created_date';
const UPDATED_AT = 'dt_modified_date';
public $primaryKey = 'pk_i_id';
protected $guarded=[];

public function course()
{
    return $this->belongsTo(VCourse::class, "fk_course_id", "pk_i_id");
}

class VCourse extends Model {

public function getDate() { return $this->hasMany(courseDate::class, "fk_course_id", "pk_i_id"); }

0 likes
4 replies
tykus's avatar

There is no reason apparent from the information provided. Aside, which Collection is empty the $allCourses Collection, or the getDates Collection(s)?

Do you have any scopes that might constrain the queries but are not apparent from your code above?

bader_mattar9's avatar

@tykus just when i call all data show this error using this code $data["courses"] = VCourse::with('getDate')->get()

Please or to participate in this conversation.