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

bobdebower's avatar

How to debug on command line using php artisan schedule:run

Hey guys i want to debug a job handle using the command line i'am using php artisan schedule:run

i want to debug $db below using the command line example = dd($db);

public function handle()
 {
  $data = DB::table('users')
    ->select('id','name')
    ->where('db_name', null)
    ->limit(10);

 foreach ( $data as $user ) {
 $name = preg_replace("/[^a-zA-Z0-9]/", "", $user->name);
 $name = substr($name, 0, 8); 

  $new_dbname = $name  + $user->id;

     }
    // IF NOT EXISTS!!

  $db = DB::statement("CREATE DATABASE IF NOT EXISTS $new_dbname;");

  dd($db);
  if ( $db !== null ) {
DB::table('users')->whereNull('db_name',$new_dbname)->update([
    'db_name' => DB::raw("CONCAT(name, '_', id)")
]);
  }

 }
0 likes
6 replies
s4muel's avatar

i would tryLog::debug() instead and examine the log file.

i thought you were talking about jobs, sorry, edited

1 like
automica's avatar

@bobdebower

public function handle()
{
    $users = DB::table('users')
        ->select('id')
        ->where('db_name', null)
        ->limit(10)->get();

    foreach ($users as $user) {

        $dbName = $user->databaseName;

        $db = DB::statement("CREATE DATABASE IF NOT EXISTS $dbName");
        if ($db !== null) {
            $user->update('db_name', $dbName);
        }
    }
}
1 like

Please or to participate in this conversation.