public function index(Request $request)
{
$data = Admin::when($request->keyword, function ($query) use ($request) {
$query->where('nama_lengkap', 'like', "%{$request->keyword}%");
})->paginate(5);
$data->appends($request->only('keyword'));
return view('admin.crud_admin.index', compact('data'));
}
Model Admin.php
protected $fillable = [
'avatar', 'nama_lengkap', 'email', 'password',
];
public function getAvatar()
{
if (!$this->avatar) {
return asset('images/default.png');
}
return asset('images/' . $this->avatar);
}
index.blade.php
<a class="nav-link dropdown-toggle dropdown-user-link" id="dropdown-user" href="javascript:void(0);"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<div class="user-nav d-sm-flex d-none">
<span class="user-name font-weight-bolder"></span>
<span class="user-status">Admin</span>
</div>
<span class="avatar"
><img class="round" src=""
alt="avatar" height="40" width="40"
/><span class="avatar-status-online"></span>
</span>
</a>
this does not appear even there is an error:
"Method Illuminate\Database\Eloquent\Collection::getAvatar does not exist. (View: C:\xampp\htdocs\Helpdesk\resources\views\admin\crud_admin\index.blade.php)"
Can you help me? please this is important to me
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire