troubleshooting Question

Could you point a way to enable/ disable an like icon depending on the user had clicked it before or not?

Avatar of Eduardo Fuerte
Eduardo FuerteFlag for Brazil asked on
36 Comments2 Solutions161 ViewsLast Modified:
Hi Experts

Could you point a way to enable/ disable an like icon depending on the user had clicked the icon before or not?

Accordingly with:

The user has the right of click the "Like" of  a photo once and after that he coudn't do nothing else, the like icon must to be disabled.
If the user reenter the page the like icon for the photo that had received a "like" must to stay disabled, also, by using the user's id.

The actual view:



	<div class='row'>

	{{ csrf_field() }}
    <input type="hidden" id="hdnCurtiu" value="{{ $curtiu }}">

        <div class="col-md-12 col-sm-12">
                <section class="row">
                        @foreach($vitrinesX->chunk(3) as $row)
                            @foreach($row as $vitrine)
                               <div class="col-sm-12 col-md-4">
                                    <div class="box-noticias">
                                       	<a href="javascript:void(0);" onclick='xxx.vitrine.abrirVitrine({{$vitrine->id}});' >
                                   	<p id="like" class="likes" onclick="xxx.vitrine.salvarEscolha({{ $vitrine->id }}, 1)">
    				                    <i class="fa fa-thumbs-up"></i> <span id="qtdeCurtiu_{{ $vitrine->id }}">{{ $vitrine->qtdeCurtiu }}</span>



	<script src="{{ asset('js/xxx/xxx.Formatadores.js').'?v='xxx(uniqid()) }}" ></script>
	<script src="{{ asset('js/xxx/xxx.Vitrine.js').'?v='xxx(uniqid()) }}" ></script>

		$(document).ready(function() {
			if($('#hdnCurtiu').val() == "1")
			else if($('#hdnCurtiu').val() == "0")


I guess when the page starts it must to be checked on the existent jQuery code

JS code for the view (where I guess it must to be checked):

Vitrine.prototype.abrirVitrine = function(id) {
    url: "/vitrine/" + id + "/obter",
    method: "GET",
    error: function() {
        "Erro ao obter a notícia.",
    success: function(data) {
      datacriacao = xxx.formatadores.DataBDParaDataBrasil(
      titulo = data.retorno.titulo;
      subtitulo = data.retorno.subtitulo;
      conteudo = data.retorno.conteudo;
      url = data.retorno.url;
      $("#image").attr("src", url);
      $("html, body").animate(
        { scrollTop: $("#datacriacao").offset().top },

Controller code (where the above JS calls the obter method):

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;

use Debugbar;
use DB;

class UserVitrine extends Model
    public function obter($user_id, $vitrine_id){
        return UserVitrine
            ::where('user_id', \DB::raw($user_id))
            ->where('vitrine_id', \DB::raw($vitrine_id))
    public function obterCurtidasPorVitrine($vitrine_id, $curtiu){

        return UserVitrine
            ::where('vitrine_id', \DB::raw($vitrine_id))
            ->where('curtiu', \DB::raw($curtiu))

Thanks in advance!
Join our community to see this answer!
Unlock 2 Answers and 36 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 36 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros