Jump to content

Capsule::table problem


Davor

Recommended Posts

Hello,

I want to get the orderId from the database based on the invoiceId directly from database using Capsule.

I don't get anything, also with try catch I don't get any errors.

Here is the code that I'm using:

use WHMCS\Database\Capsule;

$orderId = Capsule::table('tblorders')->select('id')
->where('invoiceid', $invoiceId)
->first();

 

The $invoiceId is for example 74 and there is a record in the database table tblorders that contains this invoiceId.

Can anyone see what I'm doing wrong?

 

Thanks,

Davor

 

Edited by Davor
Link to comment
Share on other sites

Found what it was.

If anyone also is having this problem (or for my future me). My solution was to ditch the Select and get the whole row and then get the id. Here is the working code:

$orderId = Capsule::table('tblorders')
->where('invoiceid', $invoiceId)
->first();


//in the code use this to get the id
$myID = $invoiceId->id

 

Link to comment
Share on other sites

On 9/16/2021 at 2:39 PM, Davor said:

Found what it was.

If anyone also is having this problem (or for my future me). My solution was to ditch the Select and get the whole row and then get the id. Here is the working code:


$orderId = Capsule::table('tblorders')
->where('invoiceid', $invoiceId)
->first();


//in the code use this to get the id
$myID = $invoiceId->id

 

hi @Davor
You can use following Query

$orderId = Capsule::table('tblorders')
->where('invoiceid', $invoiceId)
->first()->id;
Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated