We help IT Professionals succeed at work.
Get Started

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

Last Modified: 2020-02-10
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")


Open in new window

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 },

Open in new window

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))

Open in new window

Thanks in advance!
Watch Question
Most Valuable Expert 2020
Most Valuable Expert 2018
This problem has been solved!
Unlock 2 Answers and 36 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE