Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

francisMS's avatar

Convert mysql query to laravel ORM query

I want convert mysql query to laravel ORM query, anyone can help...

Here the Sql Query...

query('SELECT PAYMENT, TOTAL, TRANSID FROM PAYMENTS WHERE RECEIPT = (select ID from tickets WHERE TICKETID = ?)'

0 likes
7 replies
mushood's avatar

Do you already have Payment Model and Ticket Model?

somnathsah's avatar

You can create query something like below:

DB::table('payments', function($query) {
$query->join('tickets')
             ->on('payments.receipt', '=', 'tickets.receipt');
})
->select('payment', 'total', 'transid')
->get();

reference : https://laravel.com/docs/5.5/queries

RamjithAp's avatar

Try this

$ticketid  = 2;// hope you have this value
$data= DB::table('tickets ')
            ->where(TICKETID ,$ticketid )
            ->join('PAYMENTS as P ', 'tickets.id', '=', 'P.RECEIPT ')
            ->select('P.PAYMENT', 'P.TOTAL','P.TRANSID ')
            ->get();
francisMS's avatar

Working fine... @mushood

Here the query

$ticketQuery = Ticket::select('ID')->where('TICKETID', $ticketNo)->get();

$paymentQuery = Payment::select('PAYMENT', 'TOTAL', 'TRANSID')->where('RECEIPT',$ticket)->get();

Thanks for your support...

Please or to participate in this conversation.