Laravels Artisan::call('migrate:status') as json response
The value of $migration will be the output you see on the command line, which is sort of a table, its basically a string value which cannot be converted to json.
The question is quite old but I got the same problem and didn't find any solution so I made a little helper function to get pending migrations on the fly, maybe it will help someone else:
function getPendingMigration($migrationsFolderPath = false, $toJson = false)
{
$migrationsFolderPath = $migrationsFolderPath ?: database_path('/migrations');
$migrations = app('migrator')->getMigrationFiles($migrationsFolderPath);
$pendingMigrations = [];
foreach ($migrations as $migration => $fullpath){
if(!\Illuminate\Support\Facades\DB::table('migrations')->where('migration', $migration)->exists())
array_push($pendingMigrations, $migration);
}
return $toJson ? json_encode($pendingMigrations) : $pendingMigrations;
}