I want to delete some user, and if that user have an avatar i want to remove the avatar either. so i do like this :
public function destroy($id)
{
$user = User::findOrFail($id);
if ($user && $user->profile->avatar){
Storage::delete($user->profile->avatar);
}
User::destroy($id);
return back();
}
but when i do this it give me an error like this when user doesn't have any record in avatar tables:
"Trying to get property of non-object"
so what make me get this errors and how can i fix it. thanks.
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2zWioEU
via IFTTT
Aucun commentaire:
Enregistrer un commentaire