Skip to content

Commit f5d5c5a

Browse files
[12.x] try another way to activate Broadcast routes (#57734)
* try another way to activate Broadcast routes this command currently has 2 conditions it checks to try and activate the "channels" file in your `/bootstrap/app.php`. while this may cover a good chunk of users, it fails if the `commands:` named argument has been removed from the file. this change adds an additional check to look for the `->withRouting()` method call, which has a *very* high likelyhood of being in the file. placing it after the "commands" named argument is ideal because it maintains named argument order, but this is a good fallback. _if even this additional check fails_, it now returns an error message to the user telling them they need to manually activate the broadcast routes in their `/bootstrap/app.php` file. this will helpfully avoid confusion if the automatic enabling fails. * Update BroadcastingInstallCommand.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 5b3cc40 commit f5d5c5a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Illuminate/Foundation/Console/BroadcastingInstallCommand.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ protected function uncommentChannelsRoutesFile()
161161
'commands: __DIR__.\'/../routes/console.php\','.PHP_EOL.' channels: __DIR__.\'/../routes/channels.php\',',
162162
$appBootstrapPath,
163163
);
164+
} elseif (str_contains($content, '->withRouting(')) {
165+
(new Filesystem)->replaceInFile(
166+
'->withRouting(',
167+
'->withRouting('.PHP_EOL.' channels: __DIR__.\'/../routes/channels.php\',',
168+
$appBootstrapPath,
169+
);
170+
} else {
171+
$this->components->error('Unable to register broadcast routes. Please register them manually in ['.$appBootstrapPath.'].');
164172
}
165173
}
166174

0 commit comments

Comments
 (0)