My application accepts payments from users, but subtitles are not allowed to view the payment screen.
I have a Route::group that checks if the user is allowed to pay through Middleware. The handle function looks like this:
if(!\Auth::user()->isTeacher) { \Auth::logout(); return redirect('/login')->withErrors([$error = 'Sorry there was a problem. Please notify your School']); } return $next($request);
and isTeacher() function
if($this->school_id) { $teachers = $this->school->find($this->id)->teachers; $isTeacher = false; foreach ($teachers as $teacher) { if ($teacher->id == \Auth::user()->id) {$teacher = true;} } return $isTeacher;
}
Finally, the schoolβs relationship is as follows
return $this->hasOne('App\School', 'id', 'school_id');
The error I am getting is
LogicException in Model.php line 2667: Relations method should return an object of type Illuminate \ Database \ Eloquent \ Relations \ Relation
In the part of the error tree? it shows that this is from middleware
in Model β __ get ('isTeacher') in the line MustBeTeacherToMakePayment.php 19
which is the if statement in the first line above.
Can anyone tell me what I'm doing wrong? It drives me crazy.
source share