I Have Problem with get data
This is my code Controller
$class = DetailMentor::with('Kelas')->where('id', Auth::user()->id)->get();
Model:
protected $primaryKey = 'id_mentor';
protected $fillable = [
'id',
'id_kelas',
];
public $timestamps = true;
public function Kelas()
{
return $this->hasMany(Kelas::class, 'id_kelas','id_kelas');
}
public function User()
{
return $this->belongsTo(User::class, 'id','id');
View index
<tbody>
@forelse ($class->Kelas as $item)
<tr role="row" class="odd">
<th scope="row" class="small" class="sorting_1">{{ $loop->iteration}}.</th>
<td>{{ $item->nama_kelas }}</td>
<td>{{ $item->Jeniskelas->jenis_kelas }}</td>
<td>{{ $item->level->nama_level }}</td>
<td class="text-center">
@if ($item->status_video == 'Telah Dibuat')
<span class="badge badge-success ">Telah Dibuat</span>
@else
<span class="badge badge-danger">Belum Dibuat</span>
@endif
</td>
</tr>
@empty
@endforelse
</tbody>
Error: Property [Kelas] does not exist on this collection instance. (View: C:\laragon\www\Bootcamp\resources\views\mentor\listkelas\index.blade.php)
I want to group data kelas by id. If i use first it only takes one data, If i use get it say error. Can someone Helpme, Please! I'm new to this
[Picture: Array Return $class][1] [1]: https://i.stack.imgur.com/0fjIj.png