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;
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
add a comment |
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
add a comment |
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
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
laravel eloquent
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
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Use whereColumn()
:
public function checkVersion()
return $this->belongsToMany(
Article::class,
'articles_versions',
'user_id',
'article_id'
)->whereColumn('version', 'articles_versions.article_version');
Does it work for you?
– Jonas Staudenmeir
Mar 28 at 21:53
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Use whereColumn()
:
public function checkVersion()
return $this->belongsToMany(
Article::class,
'articles_versions',
'user_id',
'article_id'
)->whereColumn('version', 'articles_versions.article_version');
Does it work for you?
– Jonas Staudenmeir
Mar 28 at 21:53
add a comment |
Use whereColumn()
:
public function checkVersion()
return $this->belongsToMany(
Article::class,
'articles_versions',
'user_id',
'article_id'
)->whereColumn('version', 'articles_versions.article_version');
Does it work for you?
– Jonas Staudenmeir
Mar 28 at 21:53
add a comment |
Use whereColumn()
:
public function checkVersion()
return $this->belongsToMany(
Article::class,
'articles_versions',
'user_id',
'article_id'
)->whereColumn('version', 'articles_versions.article_version');
Use whereColumn()
:
public function checkVersion()
return $this->belongsToMany(
Article::class,
'articles_versions',
'user_id',
'article_id'
)->whereColumn('version', 'articles_versions.article_version');
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
add a comment |
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
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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