This code related to our group project.when i use below code it is give
Call to undefined method stdClass::subjects().I tried many ways but can not solved.following code part give the error
,{$user->subjects()->get()[1]->name}} @foreach($users as $user)
<tr><td> </td>
<td> </td>
<td> </td>
<td>,{$user->subjects()->get()[1]->name}} </td>
</tr>
@endforeach
codes of Subject.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Subject extends Model
{
protected $table='subject';
protected $fillable = ['id','name','created_at','updated_at','user_id'];
protected $primaryKey='id';
public function user(){
return $this->belongsTo('App\User');
}
codes of User.php
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
protected $table='users';
protected $fillable = [
'usertype','name','lname', 'email','dob','school','phone','gender','password','verifyToken'
];
protected $hidden = [
'password', 'remember_token',
];
)
}
public function subjects()
{
return $this->hasMany('App\Subject','user_id','id');
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire