title: Like on an user Model laravel 8
body: <p><code>enter code here</code>Hey guys i'm trying to add a like and a dislike on an user model on laravel 8, and it only works if the user liked is the authenticated user and could someone help me on how to make it possible with all user</p>
  <p>User model :</p>
  <p>this is the user model:</p>
  <pre><code> class User extends Authenticatable
      {
          use HasApiTokens, HasFactory, Notifiable;
  
      /**
       * The attributes that are mass assignable.
       *
       * @var array&lt;int, string&gt;
       */
      protected $fillable = [
          'name',
          'first_name',
          'image',
          'cover_image',
          'country_id',
          'email',
          'password',
      ];
  
      /**
       * The attributes that should be hidden for serialization.
       *
       * @var array&lt;int, string&gt;
       */
      protected $hidden = [
          'password',
          'remember_token',
      ];
  
      /**
       * The attributes that should be cast.
       *
       * @var array&lt;string, string&gt;
       */
      protected $casts = [
          'email_verified_at' =&gt; 'datetime',
      ];
  
  
  
      public function likes()
      {
          return $this-&gt;hasOne(UserLike::class,);
      }
  
  
  }
  </code></pre>
  <p>this is the like model:<br />
  &lt;?php</p>
  <pre><code>namespace App\Models;
  
  use Illuminate\Database\Eloquent\Factories\HasFactory;
  use Illuminate\Database\Eloquent\Model;
  use App\Models\User;
  
  class UserLike extends Model
  {
      use HasFactory;
      protected $fillable = [
          'user_id',
          'liked_id',
      ];
  
      public function user()
      {
          return $this-&gt;belongsTo(User::class);
      }
  }
  </code></pre>
  <p>This is the like migrations:
  &lt;?php</p>
  <pre><code>use Illuminate\Database\Migrations\Migration;
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Support\Facades\Schema;
  
  class CreateUserLike extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('user_likes', function (Blueprint $table) {
              $table-&gt;id();
              $table-&gt;integer('user_id');
              $table-&gt;integer('liked_id');
              $table-&gt;timestamps();
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::dropIfExists('user_like');
      }
  }
  </code></pre>
  <p>Controller :
  class UserLikeController extends Controller
  {
  //
  public function likeunlikeuser($id)
  {</p>
  <pre><code>        $user = User::find($id);
          if(!$user)
          {
              return response([
                  'message' =&gt; 'User not found.'
              ], 403);
          }
  
          $userlike = $user-&gt;likes()-&gt;where('user_id', auth()-&gt;user()-&gt;id)-&gt;first();
  
          // if not liked then like
          if(!$userlike)
          {
              UserLike::create([
                  'user_id' =&gt; auth()-&gt;user()-&gt;id,
                  'liked_id' =&gt; $id,
              ]);
  
              return response([
                  'message' =&gt; 'Liked'
              ], 200);
          }
          // else dislike it
          $userlike-&gt;delete();
  
          return response([
              'message' =&gt; 'Disliked'
          ], 200);
      }
  }
  </code></pre>