Giter Club home page Giter Club logo

laravelpush's Introduction

Push service laravel without PUSHER

for mac

brew cask install docker
brew install composer
brew install npm

brew uninstall gnu-sed
brew install gnu-sed --with-default-names
echo 'export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"' >> ~/.bash_profile 
#reopen terminal
composer create-project --prefer-dist laravel/laravel push
docker run --name host-redis -p 6379:6379 -d redis 
cd push 
composer require predis/predis
sed -i "s/^BROADCAST_DRIVER=.*/BROADCAST_DRIVER=redis/" .env
sed -i "s/^QUEUE_CONNECTION=.*/QUEUE_CONNECTION=redis/" .env
php artisan config:cache
php artisan make:event EventMessagePush

edit app/Events/EventMessagePush.php

<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class EventMessagePush implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $id;
    public $message;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($id,$message)
    {
        $this->id=$id;
        $this->message=$message;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('channel-name');
    }
}
php artisan make:command CommandMessagePush

edit app/Console/Commands/CommandMessagePush.php

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

use App\Events\EventMessagePush;

class CommandMessagePush extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'send:message {id} {message}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Send message to browser';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        event(new EventMessagePush(
            $this->argument('id'),
            $this->argument('message'))
        );
    }
}

ADD TO FILE resources/js/bootstrap.js

//Begin laravel Echo
import Echo from 'laravel-echo'

window.io = require('socket.io-client');

window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: window.location.hostname + ':6001'
});

window.Echo.channel('channel-name')
    .listen('EventMessagePush', (e) => {
        console.log(e);
    });
//End laravel Echo

add to file resources/views/welcome.blade.php

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}" defer></script>
npm i
npm install --save laravel-echo
npm install --save socket.io-client
npm run prod

npm install -g laravel-echo-server

laravel-echo-server init 

laravel-echo-server start 

php artisan queue:listen --tries=1

php artisan serve

open http://localhost:8000

php artisan send:mes 1 "hi it is PUSH mess"

OPEN WEB TOOLS CONSOLE

laravelpush's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.