notes_idbus = $_SESSION['user_idbus'] ?? null; if (empty($note->notes_idbus)) { $note->notes_idbus = 1; } $note->notes_iduser = $_SESSION['user_id'] ?? null; }); } /** * Scope a query to only include notes for the current business and user. * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ public function scopeCurrentUser($query) { if (session_status() === PHP_SESSION_NONE) { session_start(); } $busId = $_SESSION['user_idbus'] ?? null; if (empty($busId)) { $busId = 1; } $userId = $_SESSION['user_id'] ?? null; return $query->where('notes_idbus', $busId) ->where('notes_iduser', $userId); } /** * Get the subject that owns the note. */ public function subject() { return $this->belongsTo(Subject::class, 'notes_subject_id', 'subjects_id'); } }