0

I have a problem that I can't fix :

this request works in PHPMYADMIN

SELECT cronState.name, command.name, parameter.keyword, eventParameterValue.value
FROM cronState, commandInstance, command, eventParameterValue, parameter
WHERE cronState.id = commandInstance.cronState_id
AND commandInstance.command_id = command.id
AND eventParameterValue.commandInstance_id = commandInstance.id
AND eventParameterValue.parameter_id = parameter.id
AND cronState.id =32

it returns :

name    name            keyword     value   

on20    DigitalPinSet   State       1
on20    PwmPinSet       DutyCycle   20

and it's ALL I want.

LITTLE EDIT : I use an AJAX Request(with a state_name) to this method which should returns the query result.

Now, when I try to implement it with the Laravel Query Builder, it returns some errors.

My code:

    $cronState_id = DB::table('cronState')
        ->where('name', Input::get('state_name'))
        ->first();
    $cronEvent = DB::table('cronState')
        ->join('commandInstance', 'commandInstance.cronState_id', '=', 'cronState.id')
        ->join('command', 'commandInstance.command_id', '=', 'command.id')
        ->join('eventParameterValue', 'eventParameterValue.commandInstance_id', '=', 'commandInstance.id')
        ->join('eventParameterValue', 'eventParameterValue.parameter_id', '=', 'parameter.id')
        ->where('cronState.id', '=', $cronState_id->id)
        ->select('cronState.name', 'command.name', 'parameter.keyword', 'eventParameterValue.value');

foreach($cronEvent as $result){
        $ev =  $result['keyword'];
    }

return $ev;

The error for this code :

{"error":{"type":"ErrorException","message":"Undefined index: keyword","file":"/var/www/stage/app/controllers/EventController.php","line":48}}

if I change

foreach($cronEvent as $result){
        $ev =  $result['keyword'];
    }

return $ev;

to

return $cronEvent;

(just delete the foreach loop and rename the returning variable), I have this error :

{"error":{"type":"ErrorException","message":"Object of class Illuminate\Database\Query\Builder could not be converted to string","file":"/var/www/stage/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php","line":361}}

So, how can access to my data in the object ? Maybe my Query Builder implementation doesn't works...

Thanks for any help !

2
  • 1
    $cronEvent is a query builder object, not a result set. you need to call get(), first() or paginate() to get the result. Commented Apr 30, 2014 at 11:11
  • Yeah, sure. It was a mistake from me... i'm so dumb ahah. It works good now. Commented Apr 30, 2014 at 11:22

1 Answer 1

3

There is missing get() at the end of that query builder, thus you don't run the query at all. That's it.

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

1 Comment

I'm so stupid sometimes... 1 hour lost for that mistake. Thanks so. It works great now !

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.