Hi,
I get this error while try to show student's class in view.
'''
Call to undefined method Illuminate\Database\Query\Builder::belognsToMany() (View:
'''
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'last_name',
'father_name',
'dob',
'email',
'password',
'phone',
'address',
'admission_year',
'gender',
'photo',
'class_id',
'subject_id',
'user_type'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function grade(){
return $this->belognsToMany('App\Grade');
}
}
'''
and Here is my Grade model
'''
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Grade extends Model
{
public $table = 'classes';
protected $fillable = [
'name',
'fee',
'limit'
];
public function user(){
return $this->hasMany('App\User');
}
}
'''
Maybe the relationship is the problem. But I don't know how to relate them. I can save the class id to users table and I want o show the class or grade name based on the ID I have saved on the database to view. But I get the error.
This is what I try in view that cause the problem
'''
{{$student->grade()->name}}
'''
Can anyone tell me what is wrong ?
Thank's :)