3

I am developing a feature for an app using Laravel, and I am coming across this weird error that I can't figure out. I have the following code as a helper function to my controller, which was working just fine before I added a call to the following function:

protected function f($p){

    $cIds = $cs->select('cs.id')->get();

    $cs = DB::table('cs')
            ->select('cs.id')
            ->join('pucs', 'cs.id', '=', 'pucs.c_id')
            ->where('pucs.p_id', '=', (string)$p->id)
            ->whereIn('cs.id', $cIds)->lists('cs.id');
    return $cs;
}

where pucs has a foreign key to cs and a column called p_id, and I only want to return rows where p_id = $p->id. $p is the result of a previous query, and $p->id is an int (I think?). When I open the page on my website, I get the following error:

Missing argument 1 for Illuminate\Database\Query\Builder::lists()

Does anyone have any insight as to what might be causing this problem? My initial thought was that $p->id was an int and that was causing the problem, so I cast it to a string using the (string) operator, as well as trying strval($p->id). I'm out of ideas.

UPDATE: using pluck('cs.id') gives the same error. I thought the issue might have been (string)$p->id, but when I comment out ->where('pucs.p_id', '=', (string)$p->id) I still get the same issue. For reference, I have a very similar line of code in the same helper file:

$bIds = $bs->select('bs.id')->get();
$bs = DB::table('bs')
    ->whereIn('bs.id', $bIds)->lists('bs.id');

I'm pretty sure it was working before, even while I was getting errors on the earlier piece of code, but now it's not working either.

Anyway, the reason I'm doing this is because I have these awkward tables that have been joined and unioned with other tables, and then selected a subset of cs.id (or bs.id) from that, and I want just the result of the original tables. Also, I was getting some weird errors because MYSQL apparently has a problem sorting unioned tables by id?

4
  • I hate to be so forward... but is the error message not super clear? You called ->lists(), and that call is "Missing argument 1". Commented Mar 5, 2017 at 2:06
  • use pluck instead of lists. but also yeah I don't get the point of calling lists or pluck without an argument Commented Mar 5, 2017 at 2:58
  • So I was refactoring the code for posting on here, and that wasn't even the error I wanted to fix haha. I updated the question. Commented Mar 5, 2017 at 16:29
  • f($p){} See the extra } Commented Mar 5, 2017 at 16:31

1 Answer 1

3

When using lists(), you need to pass in the name of the key you want the values for. Normally you would call get() here instead of lists(), but if you call lists('cs.id') then you should get an array of the matching cs.id's.

Sign up to request clarification or add additional context in comments.

2 Comments

So I was refactoring the code for posting on here, and that wasn't even the error I wanted to fix haha. I updated the question.
I'm not sure what you changed about the question? I still see the same "Missing argument 1" error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.