Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to print model query in laravel

i am new in laravel and have to save the record in table , i am using this code to insert the value

$model->studentRollId = $value1;
$model->resident_permit_number = $value2;
$model->save()

i am not getting any error but record not inserting in the table , so can anyone please tell me how can i print the executed query by the $model->save(), i tried DB::getQueryLog() but its not shiwing the query log so i can fin what is the issue . thanks in advance

like image 224
Dhirendra Kumar Avatar asked Nov 17 '25 15:11

Dhirendra Kumar


2 Answers

Use ->toSql(), after your $model->save(), just do a dd($model->toSql())

Edit: Have you do a \DB::enableQueryLog();?

\DB::enableQueryLog();
$model->studentRollId = $value1;
$model->resident_permit_number = $value2;
$model->save()
dd(\DB::getQueryLog());
like image 134
SteD Avatar answered Nov 20 '25 05:11

SteD


Try This

$model->studentRollId = $value1;
$model->resident_permit_number = $value2;
$data = $model->toSql();
dd($data);
like image 24
Zeus Avatar answered Nov 20 '25 05:11

Zeus