mardi 5 novembre 2019

How to check if products is empty Laravel with javascript

I want to check if products is empty or not with javascript, when user tries to like or unlike something it should check without refreshing the page. I use eloquent , I have tried something here but it is not strong enough to work, in normal way I check like this

@if (Auth::user()->likedProducts->count() > 0 )
@else
@endif

Any one with idea on how I can fix this?

User.php

 public function likedProducts()
 {
   return $this->morphedByMany('App\Product', 'likeable');
 }  

Blade File

<a style="display: " id="item" href=""> displays products  </a>

<a style=" display: " id="item" href="">You have no products </a>

I don't know what to put in javascript, since I have no idea and I have tried to search but didn't get an answer, your help would be appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire