Laravel - compare value from pivot table with related tableCheck if belongsToMany relation exists - LaravelLaravel and pivot table to relate different modelLaravel eloquent relationship between two many to many related tablesFilter on related table with Laravel and eloquentCreating one to many relationship with pivot table of many to many relationshipRelation with pivot tableLaravel implicit binding with pivot relation on userPivotModel extends Pivot in laravel how to get the PivotModel relation dataLaravel Eloquent - querying pivot tableLaravel, where, orwhere in main table an pivot table

Why do jet engines sound louder on the ground than inside the aircraft?

Why does a tetrahedral molecule like methane have a dipole moment of zero?

Is this Android phone Android 9.0 or Android 6.0?

"This used to be my phone number"

Does unblocking power bar outlets through short extension cords increase fire risk?

Will the internet speed decrease on second router if there are multiple devices connected to primary router?

Has sea level rise slowed down?

Why can't I hear fret buzz through the amp?

What is a Romeo Word™?

Is it legal for a supermarket to refuse to sell an adult beer if an adult with them doesn’t have their ID?

How do you send money when you're not sure it's not a scam?

How to tell readers that I know my story is factually incorrect?

Why do the digits of a number squared follow a similar quotient?

Which modern firearm should a time traveler bring to be easily reproducible for a historic civilization?

Who or what determines if a curse is valid or not?

Is it possible to invoke "super" with less ambiguous results?

Can I prevent my opponent from looking at cards with Vizier of the Menagerie while I'm Mindslaving them?

How long were the Apollo astronauts allowed to breathe 100% oxygen at 1 atmosphere continuously?

I have found a mistake on someone's code published online: what is the protocol?

Last-minute canceled work-trip mean I'll lose thousands of dollars on planned vacation

Why didn't Doctor Strange restore Tony Stark after he used the Stones?

What's a German word for »Sandbagger«?

How many opportunity attacks can you make per turn before becoming exhausted?

Changing iteration variable in Do loop



Laravel - compare value from pivot table with related table


Check if belongsToMany relation exists - LaravelLaravel and pivot table to relate different modelLaravel eloquent relationship between two many to many related tablesFilter on related table with Laravel and eloquentCreating one to many relationship with pivot table of many to many relationshipRelation with pivot tableLaravel implicit binding with pivot relation on userPivotModel extends Pivot in laravel how to get the PivotModel relation dataLaravel Eloquent - querying pivot tableLaravel, where, orwhere in main table an pivot table






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have the following tables:



users:
id | name |



articles:
id | active | global | version



and pivot table



articles_versions



user_id | articles_id | article_version



In model "user" I would like to have a method that checks if in pivot table "article_version" field is equal with field "version" in "article" table.



My current method in "user" model:



public function checkVersion()

return $this->belongsToMany(
Article::class,
'articles_versions',
'user_id',
'article_id'
)
->where('version', 'articles_versions.article_version');
//OR
//->wherePivot('version', 'articles_versions.article_version');



How I can pass to "where" or "wherePivot" value to check from the related table?



Is it possible to do it?



Thank you










share|improve this question






























    1















    I have the following tables:



    users:
    id | name |



    articles:
    id | active | global | version



    and pivot table



    articles_versions



    user_id | articles_id | article_version



    In model "user" I would like to have a method that checks if in pivot table "article_version" field is equal with field "version" in "article" table.



    My current method in "user" model:



    public function checkVersion()

    return $this->belongsToMany(
    Article::class,
    'articles_versions',
    'user_id',
    'article_id'
    )
    ->where('version', 'articles_versions.article_version');
    //OR
    //->wherePivot('version', 'articles_versions.article_version');



    How I can pass to "where" or "wherePivot" value to check from the related table?



    Is it possible to do it?



    Thank you










    share|improve this question


























      1












      1








      1








      I have the following tables:



      users:
      id | name |



      articles:
      id | active | global | version



      and pivot table



      articles_versions



      user_id | articles_id | article_version



      In model "user" I would like to have a method that checks if in pivot table "article_version" field is equal with field "version" in "article" table.



      My current method in "user" model:



      public function checkVersion()

      return $this->belongsToMany(
      Article::class,
      'articles_versions',
      'user_id',
      'article_id'
      )
      ->where('version', 'articles_versions.article_version');
      //OR
      //->wherePivot('version', 'articles_versions.article_version');



      How I can pass to "where" or "wherePivot" value to check from the related table?



      Is it possible to do it?



      Thank you










      share|improve this question
















      I have the following tables:



      users:
      id | name |



      articles:
      id | active | global | version



      and pivot table



      articles_versions



      user_id | articles_id | article_version



      In model "user" I would like to have a method that checks if in pivot table "article_version" field is equal with field "version" in "article" table.



      My current method in "user" model:



      public function checkVersion()

      return $this->belongsToMany(
      Article::class,
      'articles_versions',
      'user_id',
      'article_id'
      )
      ->where('version', 'articles_versions.article_version');
      //OR
      //->wherePivot('version', 'articles_versions.article_version');



      How I can pass to "where" or "wherePivot" value to check from the related table?



      Is it possible to do it?



      Thank you







      laravel eloquent






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 18:47









      Jonas Staudenmeir

      15.3k2 gold badges12 silver badges43 bronze badges




      15.3k2 gold badges12 silver badges43 bronze badges










      asked Mar 26 at 10:51









      KlickKlick

      2554 silver badges21 bronze badges




      2554 silver badges21 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Use whereColumn():





          public function checkVersion()

          return $this->belongsToMany(
          Article::class,
          'articles_versions',
          'user_id',
          'article_id'
          )->whereColumn('version', 'articles_versions.article_version');






          share|improve this answer























          • Does it work for you?

            – Jonas Staudenmeir
            Mar 28 at 21:53










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55355339%2flaravel-compare-value-from-pivot-table-with-related-table%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Use whereColumn():





          public function checkVersion()

          return $this->belongsToMany(
          Article::class,
          'articles_versions',
          'user_id',
          'article_id'
          )->whereColumn('version', 'articles_versions.article_version');






          share|improve this answer























          • Does it work for you?

            – Jonas Staudenmeir
            Mar 28 at 21:53















          0














          Use whereColumn():





          public function checkVersion()

          return $this->belongsToMany(
          Article::class,
          'articles_versions',
          'user_id',
          'article_id'
          )->whereColumn('version', 'articles_versions.article_version');






          share|improve this answer























          • Does it work for you?

            – Jonas Staudenmeir
            Mar 28 at 21:53













          0












          0








          0







          Use whereColumn():





          public function checkVersion()

          return $this->belongsToMany(
          Article::class,
          'articles_versions',
          'user_id',
          'article_id'
          )->whereColumn('version', 'articles_versions.article_version');






          share|improve this answer













          Use whereColumn():





          public function checkVersion()

          return $this->belongsToMany(
          Article::class,
          'articles_versions',
          'user_id',
          'article_id'
          )->whereColumn('version', 'articles_versions.article_version');







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 26 at 16:10









          Jonas StaudenmeirJonas Staudenmeir

          15.3k2 gold badges12 silver badges43 bronze badges




          15.3k2 gold badges12 silver badges43 bronze badges












          • Does it work for you?

            – Jonas Staudenmeir
            Mar 28 at 21:53

















          • Does it work for you?

            – Jonas Staudenmeir
            Mar 28 at 21:53
















          Does it work for you?

          – Jonas Staudenmeir
          Mar 28 at 21:53





          Does it work for you?

          – Jonas Staudenmeir
          Mar 28 at 21:53








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55355339%2flaravel-compare-value-from-pivot-table-with-related-table%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현