How is is_student stored in the database? What are the values for yes and no/ active and inactive?
May 3, 2017
10
Level 2
Trying to get property of non-object
hi I'm a newbie,
I would like to display all Students, where Student is Active.
I build a local Scope in my Model:
public function scopeStudents()
{
return $this->where('is_student', true);
}
my Controller looks like so:
class CourseMembersController extends Controller
{
public function index(Course $course)
{
//dd($course);
$users = User::students()->get()->toArray();
return view('courses.members.index', compact('course', 'users'));
}
}
I don't understand the Error "Trying to get property of non-object".
Can someone explain me?
Level 5
Try @jbloomstrom s suggestion. I think that's a very clean way to write this scope. Also, with and without the scope take out ->toArray. Have ->get(); be the last of that statement.
Is there a particular reason why you're toarray'ing? ....sorry on my phone so no annotations or tests here.
1 like
Please or to participate in this conversation.