Member Since 3 Years Ago
Kottayam, India
3,760 experience to go until the next level!
In case you were wondering, you earn Laracasts experience when you:
Earned once you have completed your first Laracasts lesson.
Earned once you have earned your first 1000 experience points.
Earned when you have been with Laracasts for 1 year.
Earned when you have been with Laracasts for 2 years.
Earned when you have been with Laracasts for 3 years.
Earned when you have been with Laracasts for 4 years.
Earned when you have been with Laracasts for 5 years.
Earned when at least one Laracasts series has been fully completed.
Earned after your first post on the Laracasts forum.
Earned once 100 Laracasts lessons have been completed.
Earned once you receive your first "Best Reply" award on the Laracasts forum.
Earned if you are a paying Laracasts subscriber.
Earned if you have a lifetime subscription to Laracasts.
Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.
Earned once you have achieved 500 forum replies.
Earned once your experience points passes 100,000.
Earned once your experience points hits 10,000.
Earned once 1000 Laracasts lessons have been completed.
Earned once your "Best Reply" award count is 100 or more.
Earned once your experience points passes 1 million.
Earned once your experience points ranks in the top 50 of all Laracasts users.
Earned once your experience points ranks in the top 10 of all Laracasts users.
Started a new Conversation ```storage::append``` Truncating File When It Is Huge
I am trying to write a big file using Storage::append
.
This root class is inherited by 2 classes - FileTypeA
and FileTypeB
.
FileTypeA
is huge, while FileTypeB
is small.
I continuously use FileTypeA
and FileTypeB
to append to 2 different files (no threads used - so only one process writes to a file at a time).
The problem I am facing is that when class FileTypeA
tries to write the it's file using Storage::append
sometimes the file ends getting truncated in between. It works all good when FileTypeB
does the same.
So I did a bit of snooping around and noticed that Illuminate/Filesystem/Filesystem::append
uses file_put_contents
while Illuminate/Filesystem/FilesystemAdapter::append
uses it's own get
and put
functions, which I believe is the reason for this file truncation when appending a huge file.
I am using
local
driver.
local
driver and user Storage
facade which of the above append function is being called?FilesystemAdapater
class, how do I force it to use Filesystem
class?Started a new Conversation Laravel Rule To Pass If Value Is Either Hostname Or IP
I need to validate a field and pass validation if ONE of these are true:
Mandatory check - field is required.
So I made a Laravel Rule class:
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class ValidHost implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return $this->isValidFDQN($value)
|| $this->isValidIP($value);
}
private function isValidFDQN($value)
{
return preg_match('/^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$/i', $value);
}
private function isValidIP($value)
{
// check for valid ip4 or ip6
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'Invalid hostname or IP address';
}
}
Is there a way I can use Laravel's built-in "IP" validation here (in the isValidIP()
) instead of writing a regex for that. (I suck at regex).
If it works then I can validate in my controller as:
$request->validate([
'host'=>['required', 'unique', new ValidHost]
]);
Replied to How To Submit Form Using Jetstream/Inertia
I got it to work another way.
saveNewKeyInertia()
{
this.form.post(route('keys.store').url(), {
preserveScroll: true,
onSuccess: (response) => {
if(!this.form.hasErrors())
{
this.addKeyModal = false;
this.$emit("created");
}
else
this.focusField();
}
});
},
Coupled with:
public function store(Request $request)
{
$request->validate([
'name' => 'required|string|min:4',
'public_key' => ['required', 'string', new IsValidPublicKey, new HasUniqueSshKey]
]);
$SshKey = new SshKey($request->only('name'));
$SshKey->forceFill($request->only(['public_key', 'private_key']));
$request->user()->addSshKey($SshKey);
return $request->wantsJson()
? new JsonResponse(compact('SshKey'), 200)
: back()->with('status', 'ssh-key-added');
}
Previously my return statement looked like this:
return compact('SshKey');
Started a new Conversation How To Submit Form Using Jetstream/Inertia
I am using Laravel 8 with jetstream & inertia.
I have a "create" form that is on a modal and when I try to submit the form using axios, it works as usual. But when I use Inertia, another modal pop with withe below response. Why is that, and how do I fix it?
Code submitting via Inertia
saveNewKeyInertia()
{
this.form.post(route('keys.store').url(), {
preserveScroll: true,
})
.then(repsonse => {
this.clearForm();
this.addKeyModal = false;
this.$emit("created");
})
.error(error => {
this.form.error = error;
});
}
Code submitting via Axios
saveNewKeyAxios()
{
axios.post(route('keys.store').url(), {
name : this.form.name,
public_key : this.form.public_key,
})
.then(repsonse => {
this.clearForm();
this.addKeyModal = false;
this.$emit("created");
})
.error(error => {
this.form.error = error;
});
}
Screen I get when submitting via Inertia:
Also it tells this in the response:
All Inertia.js requests must receive a valid Inertia.js response, however, a return plain JSON response was received.
How do I make sure it is handled properly? And how do I make sure new modal doesn't open for form submission?
Replied to Laravel Jetstream Inertia Returing Data From Axios Request
I have the same issue as well.
Replied to Composer Detects Wrong Php Version
Thanks for the pointer.
I checked the valet NGINX config
server {
listen 127.0.0.1:80;
server_name vpn.test www.vpn.test *.vpn.test;
return 301 https://$host$request_uri;
}
server {
listen 127.0.0.1:443 ssl http2;
server_name vpn.test www.vpn.test *.vpn.test;
root /;
charset utf-8;
client_max_body_size 512M;
http2_push_preload on;
location /41c270e4-5535-4daa-b23e-c269744c2f45/ {
internal;
alias /;
try_files $uri $uri/;
}
ssl_certificate "/Users/mathewparet/.config/valet/Certificates/vpn.test.crt";
ssl_certificate_key "/Users/mathewparet/.config/valet/Certificates/vpn.test.key";
location / {
rewrite ^ "/Users/mathewparet/.composer/vendor/laravel/valet/server.php" last;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log "/Users/mathewparet/.config/valet/Log/nginx-error.log";
error_page 404 "/Users/mathewparet/.composer/vendor/laravel/valet/server.php";
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass "unix:/Users/mathewparet/.config/valet/valet.sock";
fastcgi_index "/Users/mathewparet/.composer/vendor/laravel/valet/server.php";
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME "/Users/mathewparet/.composer/vendor/laravel/valet/server.php";
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.ht {
deny all;
}
}
server {
listen 127.0.0.1:60;
server_name vpn.test www.vpn.test *.vpn.test;
root /;
charset utf-8;
client_max_body_size 128M;
add_header X-Robots-Tag 'noindex, nofollow, nosnippet, noarchive';
location /41c270e4-5535-4daa-b23e-c269744c2f45/ {
internal;
alias /;
try_files $uri $uri/;
}
location / {
rewrite ^ "/Users/mathewparet/.composer/vendor/laravel/valet/server.php" last;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log "/Users/mathewparet/.config/valet/Log/nginx-error.log";
error_page 404 "/Users/mathewparet/.composer/vendor/laravel/valet/server.php";
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass "unix:/Users/mathewparet/.config/valet/valet.sock";
fastcgi_index "/Users/mathewparet/.composer/vendor/laravel/valet/server.php";
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME "/Users/mathewparet/.composer/vendor/laravel/valet/server.php";
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.ht {
deny all;
}
}
This is what it uses for PHP:
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass "unix:/Users/mathewparet/.config/valet/valet.sock";
fastcgi_index "/Users/mathewparet/.composer/vendor/laravel/valet/server.php";
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME "/Users/mathewparet/.composer/vendor/laravel/valet/server.php";
fastcgi_param PATH_INFO $fastcgi_path_info;
}
I don't know where to go from here.
Started a new Conversation Composer Detects Wrong Php Version
I have php 7.3 installed. It is correctly detected by terminal and in artisan:
mathewparet$ php -v
PHP 7.3.25 (cli) (built: Nov 30 2020 14:36:22) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.25, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.25, Copyright (c) 1999-2018, by Zend Technologies
mathewparet$
mathewparet$ php artisan tinker
Psy Shell v0.10.4 (PHP 7.3.25 — cli) by Justin Hileman
>>> PHP_VERSION_ID
=> 70325
>>> PHP_VERSION
=> "7.3.25"
>>> exit
Exit: Goodbye
mathewparet$
But when calling the website over the browser I get:
Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.3.0". You are running 7.2.34. in /Users/mathewparet/Projects/vpn/vendor/composer/platform_check.php on line 24
I am running on Mac BigSur + Valet
Replied to Dusk Not Identifying VUE Components?
Thanks @bugsysha , your reply gave me a clue. I increased the pause time and it worked :)
Replied to Dusk Not Identifying VUE Components?
The pause is there on purpose. Only one screen of the page is "visible" when it loads and when the user scrolls the page elements fade in.
So initially I didn't have the pause. But the text wasn't detected. So I thought it was because of the fade-in animation. So the pause was to make sure the elements are visible by then.
Started a new Conversation Dusk Not Identifying VUE Components?
I have this dusk test class:
public function testRegPageAsksForInvitationCodeIfInviteOnly()
{
$this->browse(function (Browser $browser) {
$browser->visit('/')
->driver->executeScript('window.scrollTo(0, 2100);');
$browser->pause(500)->assertSee("Invitation Code");
});
}
But it fails to detect "Invitation Code".
However, the screenshot generated by dusk has the text.
What am I missing?
Started a new Conversation BroadcastExcepetion On PusherBroadcaster.php:121 When Trying To Broadcast An Event Using Laravel-Websockets
I'm trying to use Laravel-Websockets for broadcasting. I had some trouble getting the socket connected, but now that is working. Now this is where I am stuck.
Socket connection works:
Starting the WebSocket server on port 6001...
New connection opened for app key gkey.
Connection id 716018866.942584912 sending message {"event":"pusher:connection_established","data":"{\"socket_id\":\"716018866.942584912\",\"activity_timeout\":30}"}
gid: connection id 716018866.942584912 received message: {"event":"pusher:ping","data":{}}.
Connection id 716018866.942584912 sending message {"event":"pusher:pong"}
gid: connection id 716018866.942584912 received message: {"event":"pusher:ping","data":{}}.
Connection id 716018866.942584912 sending message {"event":"pusher:pong"}
I created an event - OvpnStatusUpdated
:
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class OvpnStatusUpdated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $connections;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($connections)
{
$this->connections = $connections;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('OvpnStatus');
}
}
But when I invoke the event, I get an exception:
Psy Shell v0.10.0 (PHP 7.3.11 — cli) by Justin Hileman
>>> use App\Events\OvpnStatusUpdated;
>>> event(new OvpnStatusUpdated('hi'));
=> [
null,
]
[2020-09-27 19:30:06] local.ERROR: {"exception":"[object] (Illuminate\Broadcasting\BroadcastException(code: 0): at /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php:121)
[stacktrace]
#0 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastEvent.php(64): Illuminate\Broadcasting\Broadcasters\PusherBroadcaster->broadcast(Array, 'App\\Events\\Ovpn...', Array)
#1 [internal function]: Illuminate\Broadcasting\BroadcastEvent->handle(Object(Illuminate\Broadcasting\Broadcasters\PusherBroadcaster))
#2 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#3 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Container/Util.php(36): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#4 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
#5 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#6 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Container/Container.php(592): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#7 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#8 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
#9 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
#10 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#11 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(83): Illuminate\Bus\Dispatcher->dispatchNow(Object(Illuminate\Broadcasting\BroadcastEvent), false)
#12 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Queue\CallQueuedHandler->Illuminate\Queue\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
#13 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
#14 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(85): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#15 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(59): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware(Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Broadcasting\BroadcastEvent))
#16 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(98): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#17 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(356): Illuminate\Queue\Jobs\Job->fire()
#18 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(306): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#19 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(132): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#20 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(112): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#21 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(96): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#22 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#23 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#24 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Container/Util.php(36): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#25 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
#26 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#27 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Container/Container.php(592): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#28 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Console/Command.php(134): Illuminate\Container\Container->call(Array)
#29 /Users/mathewparet/Projects/vpn-self-service/vendor/symfony/console/Command/Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#30 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#31 /Users/mathewparet/Projects/vpn-self-service/vendor/symfony/console/Application.php(912): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#32 /Users/mathewparet/Projects/vpn-self-service/vendor/symfony/console/Application.php(264): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#33 /Users/mathewparet/Projects/vpn-self-service/vendor/symfony/console/Application.php(140): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#34 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Console/Application.php(93): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#35 /Users/mathewparet/Projects/vpn-self-service/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(130): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#36 /Users/mathewparet/Projects/vpn-self-service/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#37 {main}
"}
I did a bit of debugging on PusherBroadcaster.php
and found that error is thrown from the broadcast method and the values of each variable passed to $this->pusher->trigger()
seems ok except that $socket
is null. I assume this is what is causing the trigger to fail.
public function broadcast(array $channels, $event, array $payload = [])
{
$socket = Arr::pull($payload, 'socket');
$response = $this->pusher->trigger(
$this->formatChannels($channels), $event, $payload, $socket, true
);
if ((is_array($response) && $response['status'] >= 200 && $response['status'] <= 299)
|| $response === true) {
return;
}
throw new BroadcastException(
is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']
);
}
I am stuck and I do not know how to move forward.
Replied to Laravel Echo + Beyondcode Websockets WsPort Not Respected
Tried updating the echo config as suggested, I still have the same issue:
import Echo from "laravel-echo"
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'gkey',
wsHost: window.location.hostname,
wssPort: 6001,
forceTLS: false,
disableStats: true,
enabledTransports: ['ws'],
});
From the developer console, I see that the request is still going via wss
Replied to Laravel Echo + Beyondcode Websockets WsPort Not Respected
Yes, the websocket server is running
My pusher config is:
.env
PUSHER_APP_ID=gid
PUSHER_APP_KEY=gkey
PUSHER_APP_SECRET=gsecret
BROADCAST_DRIVER=pusher
apps/broadcasting.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Broadcaster
|--------------------------------------------------------------------------
|
| This option controls the default broadcaster that will be used by the
| framework when an event needs to be broadcast. You may set this to
| any of the connections defined in the "connections" array below.
|
| Supported: "pusher", "redis", "log", "null"
|
*/
'default' => env('BROADCAST_DRIVER', 'null'),
/*
|--------------------------------------------------------------------------
| Broadcast Connections
|--------------------------------------------------------------------------
|
| Here you may define all of the broadcast connections that will be used
| to broadcast events to other systems or over websockets. Samples of
| each available type of connection are provided inside this array.
|
*/
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'useTLS' => false,
],
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
'log' => [
'driver' => 'log',
],
'null' => [
'driver' => 'null',
],
],
];
apps/websockets.php (no changes from the vendor file)
<?php
use BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize;
return [
/*
* Set a custom dashboard configuration
*/
'dashboard' => [
'port' => env('LARAVEL_WEBSOCKETS_PORT', 6001),
],
/*
* This package comes with multi tenancy out of the box. Here you can
* configure the different apps that can use the webSockets server.
*
* Optionally you specify capacity so you can limit the maximum
* concurrent connections for a specific app.
*
* Optionally you can disable client events so clients cannot send
* messages to each other via the webSockets.
*/
'apps' => [
[
'id' => env('PUSHER_APP_ID'),
'name' => env('APP_NAME'),
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'path' => env('PUSHER_APP_PATH'),
'capacity' => null,
'enable_client_messages' => false,
'enable_statistics' => true,
],
],
/*
* This class is responsible for finding the apps. The default provider
* will use the apps defined in this config file.
*
* You can create a custom provider by implementing the
* `AppProvider` interface.
*/
'app_provider' => BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider::class,
/*
* This array contains the hosts of which you want to allow incoming requests.
* Leave this empty if you want to accept requests from all hosts.
*/
'allowed_origins' => [
//
],
/*
* The maximum request size in kilobytes that is allowed for an incoming WebSocket request.
*/
'max_request_size_in_kb' => 250,
/*
* This path will be used to register the necessary routes for the package.
*/
'path' => 'laravel-websockets',
/*
* Dashboard Routes Middleware
*
* These middleware will be assigned to every dashboard route, giving you
* the chance to add your own middleware to this list or change any of
* the existing middleware. Or, you can simply stick with this list.
*/
'middleware' => [
'web',
Authorize::class,
],
'statistics' => [
/*
* This model will be used to store the statistics of the WebSocketsServer.
* The only requirement is that the model should extend
* `WebSocketsStatisticsEntry` provided by this package.
*/
'model' => \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry::class,
/**
* The Statistics Logger will, by default, handle the incoming statistics, store them
* and then release them into the database on each interval defined below.
*/
'logger' => BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger::class,
/*
* Here you can specify the interval in seconds at which statistics should be logged.
*/
'interval_in_seconds' => 60,
/*
* When the clean-command is executed, all recorded statistics older than
* the number of days specified here will be deleted.
*/
'delete_statistics_older_than_days' => 60,
/*
* Use an DNS resolver to make the requests to the statistics logger
* default is to resolve everything to 127.0.0.1.
*/
'perform_dns_lookup' => false,
],
/*
* Define the optional SSL context for your WebSocket connections.
* You can see all available options at: http://php.net/manual/en/context.ssl.php
*/
'ssl' => [
/*
* Path to local certificate file on filesystem. It must be a PEM encoded file which
* contains your certificate and private key. It can optionally contain the
* certificate chain of issuers. The private key also may be contained
* in a separate file specified by local_pk.
*/
'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null),
/*
* Path to local private key file on filesystem in case of separate files for
* certificate (local_cert) and private key.
*/
'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null),
/*
* Passphrase for your local_cert file.
*/
'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', null),
],
/*
* Channel Manager
* This class handles how channel persistence is handled.
* By default, persistence is stored in an array by the running webserver.
* The only requirement is that the class should implement
* `ChannelManager` interface provided by this package.
*/
'channel_manager' => \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManagers\ArrayChannelManager::class,
];
Replied to Laravel Echo + Beyondcode Websockets WsPort Not Respected
Thanks for spotting that @sinnbeck . Now The URL seems correct, but socket connection is failing. Firewall is open though. I am not sure how to debug this. Developer console shows this error:
WebSocket connection to 'wss://vpn-self-service.test:6001/app/gkey?protocol=7&client=js&version=7.0.0&flash=false' failed: WebSocket is closed before the connection is established.
Started a new Conversation Laravel Echo + Beyondcode Websockets WsPort Not Respected
Laravel Echo + Beyondcode Websockets not working as expected.
My echo initialization in app.js is:
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'gkey',
wsHost: window.location.hostname,
wsPort: 6001,
forceTLS: false,
disableStats: true,
});
This wsPort is not being respected at all:
As you see wsPort isn't accepted!