How to fix laravel relationship query where clause?Laravel 4 Query Builder: LEFT JOIN … AND … queryHow to Create Multiple Where Clause Query Using Laravel Eloquent?Laravel query multiple eloquent relationshipsLaravel 4 belongsToMany Relationship Returns EmptyDescending model relationship laravelLoad laravel model where relationship has conditionLaravel: How to write a join count query on belongsToMany relationships?Laravel query builder orderBy not orderingtoSql() on Eloquent Relationship returning `where id = null`Laravel: Proper Querying Many to Many Relationships

Solve equation using Mathematica

Create two random teams from a list of players

How can flights operated by the same company have such different prices when marketed by another?

Word for soundtrack music which is part of the action of the movie

Raindrops in Python

How can you tell the version of Ubuntu on a system in a .sh (bash) script?

Using Python in a Bash Script

Easy way to get process from window

What Marvel character has this 'W' symbol?

Coworker mumbles to herself when working, how to ask her to stop?

How to foreshadow to avoid a 'deus ex machina'-construction

Would people understand me speaking German all over Europe?

How did astronauts using rovers tell direction without compasses on the Moon?

What clothes would flying-people wear?

Typesetting numbers above, below, left, and right of a symbol

How to innovate in OR

Unknown indication below upper stave

Can drawing a weapon be part of ANY kind of move action or just moving?

Patio gate not at right angle to the house

Can I attune a Circlet of Human Perfection to my animated skeletons to allow them to blend in and speak?

Why tantalum for the Hayabusa bullets?

What is the highest achievable score in Catan

Should students have access to past exams or an exam bank?

Why are we moving in circles with a tandem kayak?



How to fix laravel relationship query where clause?


Laravel 4 Query Builder: LEFT JOIN … AND … queryHow to Create Multiple Where Clause Query Using Laravel Eloquent?Laravel query multiple eloquent relationshipsLaravel 4 belongsToMany Relationship Returns EmptyDescending model relationship laravelLoad laravel model where relationship has conditionLaravel: How to write a join count query on belongsToMany relationships?Laravel query builder orderBy not orderingtoSql() on Eloquent Relationship returning `where id = null`Laravel: Proper Querying Many to Many Relationships






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








0















I am trying to get data from the 'files' table through the 'computer_files' pivot table but the query puts an 'is null' into the query and therefore it doesn't return with the data. However, if I change the is null to an ID and run it as an SQL command it does give the data back.



I have tried going through the laravel docs but it didn't help. What I don't want to do is to use raw queries.



This is the files relationship function:



public function files()
return $this->belongsToMany('AppFile', 'computer_files', 'computer_id', 'file_id');



This is what I do to get the data and currently gives back an empty collection:



$computer = Computer::where('computer_id', session('computer_id'))->first();
pr($computer->files);
die;


Also the 'toSql()' gives this:



select * from `files` inner join `computer_files` on `files`.`id` = `computer_files`.`file_id` where `computer_files`.`computer_id` is null


I expect to see an ID in the query instead of 'is null' so then it will give back the results that I need.










share|improve this question
























  • I would guess your session('computer_id') is null.

    – GTCrais
    Mar 26 at 21:43











  • already checked on that and it is not because that is being set when you login and if i set it to a number it is still the same. also if it would be null then the '$computer' would be null and therefore the files variable would fail.

    – M4ST3RX
    Mar 26 at 21:58












  • computer_id is the primary key in the computers table, right? Have you set protected $primaryKey = 'computer_id'; in the Computer model?

    – Jonas Staudenmeir
    Mar 26 at 22:19












  • yes that is the primary key and i did not set it. but as soon as I did the query changed to where `computer_files`.`computer_id` = ?. Thanks

    – M4ST3RX
    Mar 26 at 22:33

















0















I am trying to get data from the 'files' table through the 'computer_files' pivot table but the query puts an 'is null' into the query and therefore it doesn't return with the data. However, if I change the is null to an ID and run it as an SQL command it does give the data back.



I have tried going through the laravel docs but it didn't help. What I don't want to do is to use raw queries.



This is the files relationship function:



public function files()
return $this->belongsToMany('AppFile', 'computer_files', 'computer_id', 'file_id');



This is what I do to get the data and currently gives back an empty collection:



$computer = Computer::where('computer_id', session('computer_id'))->first();
pr($computer->files);
die;


Also the 'toSql()' gives this:



select * from `files` inner join `computer_files` on `files`.`id` = `computer_files`.`file_id` where `computer_files`.`computer_id` is null


I expect to see an ID in the query instead of 'is null' so then it will give back the results that I need.










share|improve this question
























  • I would guess your session('computer_id') is null.

    – GTCrais
    Mar 26 at 21:43











  • already checked on that and it is not because that is being set when you login and if i set it to a number it is still the same. also if it would be null then the '$computer' would be null and therefore the files variable would fail.

    – M4ST3RX
    Mar 26 at 21:58












  • computer_id is the primary key in the computers table, right? Have you set protected $primaryKey = 'computer_id'; in the Computer model?

    – Jonas Staudenmeir
    Mar 26 at 22:19












  • yes that is the primary key and i did not set it. but as soon as I did the query changed to where `computer_files`.`computer_id` = ?. Thanks

    – M4ST3RX
    Mar 26 at 22:33













0












0








0








I am trying to get data from the 'files' table through the 'computer_files' pivot table but the query puts an 'is null' into the query and therefore it doesn't return with the data. However, if I change the is null to an ID and run it as an SQL command it does give the data back.



I have tried going through the laravel docs but it didn't help. What I don't want to do is to use raw queries.



This is the files relationship function:



public function files()
return $this->belongsToMany('AppFile', 'computer_files', 'computer_id', 'file_id');



This is what I do to get the data and currently gives back an empty collection:



$computer = Computer::where('computer_id', session('computer_id'))->first();
pr($computer->files);
die;


Also the 'toSql()' gives this:



select * from `files` inner join `computer_files` on `files`.`id` = `computer_files`.`file_id` where `computer_files`.`computer_id` is null


I expect to see an ID in the query instead of 'is null' so then it will give back the results that I need.










share|improve this question














I am trying to get data from the 'files' table through the 'computer_files' pivot table but the query puts an 'is null' into the query and therefore it doesn't return with the data. However, if I change the is null to an ID and run it as an SQL command it does give the data back.



I have tried going through the laravel docs but it didn't help. What I don't want to do is to use raw queries.



This is the files relationship function:



public function files()
return $this->belongsToMany('AppFile', 'computer_files', 'computer_id', 'file_id');



This is what I do to get the data and currently gives back an empty collection:



$computer = Computer::where('computer_id', session('computer_id'))->first();
pr($computer->files);
die;


Also the 'toSql()' gives this:



select * from `files` inner join `computer_files` on `files`.`id` = `computer_files`.`file_id` where `computer_files`.`computer_id` is null


I expect to see an ID in the query instead of 'is null' so then it will give back the results that I need.







laravel eloquent relationship






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 21:40









M4ST3RXM4ST3RX

137 bronze badges




137 bronze badges















  • I would guess your session('computer_id') is null.

    – GTCrais
    Mar 26 at 21:43











  • already checked on that and it is not because that is being set when you login and if i set it to a number it is still the same. also if it would be null then the '$computer' would be null and therefore the files variable would fail.

    – M4ST3RX
    Mar 26 at 21:58












  • computer_id is the primary key in the computers table, right? Have you set protected $primaryKey = 'computer_id'; in the Computer model?

    – Jonas Staudenmeir
    Mar 26 at 22:19












  • yes that is the primary key and i did not set it. but as soon as I did the query changed to where `computer_files`.`computer_id` = ?. Thanks

    – M4ST3RX
    Mar 26 at 22:33

















  • I would guess your session('computer_id') is null.

    – GTCrais
    Mar 26 at 21:43











  • already checked on that and it is not because that is being set when you login and if i set it to a number it is still the same. also if it would be null then the '$computer' would be null and therefore the files variable would fail.

    – M4ST3RX
    Mar 26 at 21:58












  • computer_id is the primary key in the computers table, right? Have you set protected $primaryKey = 'computer_id'; in the Computer model?

    – Jonas Staudenmeir
    Mar 26 at 22:19












  • yes that is the primary key and i did not set it. but as soon as I did the query changed to where `computer_files`.`computer_id` = ?. Thanks

    – M4ST3RX
    Mar 26 at 22:33
















I would guess your session('computer_id') is null.

– GTCrais
Mar 26 at 21:43





I would guess your session('computer_id') is null.

– GTCrais
Mar 26 at 21:43













already checked on that and it is not because that is being set when you login and if i set it to a number it is still the same. also if it would be null then the '$computer' would be null and therefore the files variable would fail.

– M4ST3RX
Mar 26 at 21:58






already checked on that and it is not because that is being set when you login and if i set it to a number it is still the same. also if it would be null then the '$computer' would be null and therefore the files variable would fail.

– M4ST3RX
Mar 26 at 21:58














computer_id is the primary key in the computers table, right? Have you set protected $primaryKey = 'computer_id'; in the Computer model?

– Jonas Staudenmeir
Mar 26 at 22:19






computer_id is the primary key in the computers table, right? Have you set protected $primaryKey = 'computer_id'; in the Computer model?

– Jonas Staudenmeir
Mar 26 at 22:19














yes that is the primary key and i did not set it. but as soon as I did the query changed to where `computer_files`.`computer_id` = ?. Thanks

– M4ST3RX
Mar 26 at 22:33





yes that is the primary key and i did not set it. but as soon as I did the query changed to where `computer_files`.`computer_id` = ?. Thanks

– M4ST3RX
Mar 26 at 22:33












0






active

oldest

votes










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%2f55366620%2fhow-to-fix-laravel-relationship-query-where-clause%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using 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%2f55366620%2fhow-to-fix-laravel-relationship-query-where-clause%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권, 지리지 충청도 공주목 은진현