0

i want to get all row by all() and into foreach i want to get fields of other table in query builder.

$getResult = webLinks::all();

$result = array();

foreach ($getResult as $value) 
{
   $query = DB::table('webInformation')
            ->where('webLink', '=', $value->id)
            ->get();
    $r['site']  = $value->webLink;
    $r['webLink']  = $query->webLink; //I GET ERROR                 
    $result[] = $r;
}

in this coomand i can not save webLink of webInformation table into array.

i'm try this:

$r['webLink']  = $query->webLink;

or

$r['webLink']  = $query['webLink'];

how to fix this problem?

Result of that :

Array
(
    [0] => stdClass Object
        (
            [id] => 2
            [webLink] => 1
            [updated_at] => 2014-03-13 10:20:16
            [created_at] => 2014-03-13 10:20:16
        )

    [1] => stdClass Object
        (
            [id] => 3
            [webLink] => 1
            [updated_at] => 2014-03-13 10:25:32
            [created_at] => 2014-03-13 10:25:32
        )

)

1 Answer 1

2

->get() returns an array of all hits found. If you only want the first result you can use ->first() instead.

foreach ($getResult as $value) 
{
   $query = DB::table('webInformation')
            ->where('webLink', '=', $value->id)
            ->first();
    $r['site']  = $value->webLink;
    $r['webLink']  = $query->webLink;            
    $result[] = $r;
}
Sign up to request clarification or add additional context in comments.

Comments

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.