Dronax

Experience

8,110

0 Best Reply Awards

  • Member Since 6 Months Ago
  • 73 Lessons Completed
  • 0 Favorites

14th May, 2018

Dronax started a new conversation Job Check Server For Stats.. • 4 months ago

Hello all. I want release checker server for stats in monitoring. In database I havea lot of server records. I created job ServerCheck, and I writed code:

    public function handle()
    {
        $servers = Server::all();
        foreach($servers as $server) {
            $stats = getMcServer($server->ip, $server->port);
            $server->status = $stats ? 1 : 0;
            if($stats['icon']) { $server->icon = $stats['icon']; }
            $server->players_online = $stats['online'] ? $stats['online'] : 0;
            $server->max_players = $stats['max'] ? $stats['max'] : 0;
            $server->last_check = Carbon::now();
            $server->save();
        }
    }

And I sheduled this job:

$schedule->job(new ServerCheck)->everyTenMinutes();

When job running, in 60 seconds I get timeout. I think, that this is due to the fact that many servers in database. You know how to do it right?

12th May, 2018

Dronax left a reply on How I Can Do Dynamic Banner • 4 months ago

@AlexDemin In my banner I have multiple text on up, center e.t.c And I have online with rule css. This not help me..

Dronax started a new conversation How I Can Do Dynamic Banner • 4 months ago

Hello all, I want do dynamic banner:

Example: http://status.minecraftservers.org/ice/497376.png

I use Image Intervention Laravel: http://image.intervention.io/api/insert I have background of banner. And I need add text and icon, how in banner example.

How I can do this?

11th May, 2018

Dronax left a reply on Get Order By Position • 4 months ago

@Vilfago you solution not working. I get eror:

Object of class App\Models\Server could not be converted to int

    public function getRankAttribute()
    {
        $ranks = $this->query()
        ->select('id')
        ->orderByDesc('balls')
        ->orderByDesc('votes')
        ->orderByDesc('created_at')
        ->get();
        return $ranks->search($this->id) + 1;
    }

Dronax started a new conversation Get Order By Position • 4 months ago

Hello, How In laravel, I can get Order By position column?

Example:

`SELECT * FROM posts ORDER BY votes DESC

How get position in table by order for every post?

10th May, 2018

Dronax left a reply on Get Posts By Balls, Rating, Votes And Rating Count • 4 months ago

@Vilfago how write position to database? I need do query +1 in column position, when votes or balls +1 ?

Dronax left a reply on Get Posts By Balls, Rating, Votes And Rating Count • 4 months ago

@Vilfago but this will be correctly? I know, that need write to database positions, or not?

Dronax left a reply on Get Posts By Balls, Rating, Votes And Rating Count • 4 months ago

Ok, but how I can get position, on the page of the post? Example OrderBy #1 post, positon is 2. How I can get this position on the page post, where I get posts with:

Post::findFirstOrFail($id) ?

9th May, 2018

Dronax started a new conversation Get Records By Rating. • 4 months ago

Hello all. I have table posts with top posts users. All have column: votes, balls, and rating count. I need get average count of votes and rating_count.

Rating count can be maximum 5. But votes can be not limited.

I want show posts by criteria:

First posts show by balls. Other posts by average rating_count and votes.

Example:

I have 3 posts:

  1. #1 Post - votes = 100, rating_count = 2, balls = 0;
  2. #2 Post - votes = 200, rating_count = 4, balls = 1;
  3. #3 Post - votes = 250, rating_count = , 5, balls = 5;
  4. #4 Post - votes = 260, rating_count = 2, balls = 0;

I need show this posts in the following order:

1 place: post #3 - because balls 5 2 place: post #2 - because balls 1 and others places by average value of rating_count and votes..

How I can realease this?

Do you have any ideas?

13th March, 2018

Dronax started a new conversation GetRouteByKeyName Another Model Laravel • 6 months ago

I have two models:

  • Categories
  • CategoriesTranslations

In model categories I writed:

    public function getRouteKeyName(){
        return 'alias';
    }

Column alias in model CategoriesTranslations. I need relationship?

Column alias belogns model CategoriesTranslations. How I can return alias from model CategoriesTranslations? My code is not working.

10th March, 2018

Dronax started a new conversation How In Laravel Register Service Worker? • 6 months ago

Hello. I want use service-workers:

https://developers.google.com/web/fundamentals/primers/service-workers/ But How I can search service worker js for laravel? If I install default service-worker, sessions and cookies in laravel stop working..

3rd March, 2018

Dronax left a reply on Laravel Mark Message Is Seen For Users • 6 months ago

How I can check read/unread messages?

Dronax left a reply on Laravel Mark Message Is Seen For Users • 6 months ago

@crnkovic but conditions with read/unread messages?

Dronax left a reply on Laravel Mark Message Is Seen For Users • 6 months ago

Please help me

Dronax started a new conversation Laravel Mark Message Is Seen For Users • 6 months ago

Hello all. I develop new messages system and I can't mark correctly messages is seen, when user click on textarea.

For chat I use this package: https://github.com/musonza/chat

I have code:

App.js


/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');

window.Vue = require('vue');
// ES6
import Vue from 'vue'
import VueChatScroll from 'vue-chat-scroll'
Vue.use(VueChatScroll)

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

Vue.component('message', require('./components/message.vue'));

const app = new Vue({
    el: '#app',
    data:{
        message: '',
        convId: $('meta[name=convId]').attr('content'),
        user: {
            userId: $('meta[name=userId]').attr('content'),
            name: $('meta[name=name]').attr('content'),
            avatar: $('meta[name=avatar]').attr('content'),
        },
        chat: {
            message: [],
            messageId: [],
            user: [],
            time: [],
            seen: [],
        },
        typing: '',
    },
    watch: {
        message() {
            Echo.private('mc-chat-conversation.' + this.convId)
                .whisper('typing', {
                    name: this.message
                });
        }
    },
    methods: {
        seenMessage() {
            //console.log(this.chat.user);
            //if(this.chat.message.length != 0 && this.user.userId == this.chat.user.id) {
                $('li').removeClass('unread');
                axios.post('/setMessagesSeen/' + $('.messages-list > li:last').attr('messageid'))
                .then( response => {  }) 
                .catch( response => { console.log(response) } )
            //}
        },
        send(){
            if(this.message.length != 0 && this.message.length <= 4000) {
                this.chat.message.push(this.message);
                this.chat.user.push(this.user);
                this.chat.time.push(this.getTime());
                //this.chat.messageId.push('2131');
                this.chat.seen.push(0);
                axios.post('/sendMessage/' + this.convId, {
                    message: this.message,
                  })
                  .then(response => {
                    console.log(response);
                    this.message = '';
                  })
                  .catch(error => {
                    console.log(error);
                  });
            }
        },
        getTime() {
            let time = new Date();
            return time.getHours() + ':' + time.getMinutes();
        }
    },

    mounted() {
        Echo.private('mc-chat-conversation.' + this.convId)
            .listen('.Musonza\Chat\Messages\MessageWasSent', (e) => {
                // this.chat.message.push(e.message);
                // this.chat.user.push(e.user.conversation.users);
                // this.chat.time.push(this.getTime());
                var users = e.message.conversation.users;
                this.chat.messageId.push(e.message.id);
                Object.keys(users).map(function(objectKey, index) {
                    var value = users[objectKey];
                    if(value.id != this.user.userId && e.message.user_id != this.user.userId) {
                        document.getElementById('newmessage').play();
                        flashTitle("У вас новое сообщение", 10); // toggles it 10 times.../
                        this.chat.message.push(e.message.body);
                        //this.chat.seen.push(0);
                        this.chat.user.push(value);
                        this.chat.time.push(this.getTime());
                        //console.log(value);
                    }
                }, this);
                //console.log(e.message);
            })
            .listenForWhisper('typing', (e) => {
                if(e.name != '') {
                    this.typing = 'Набирает сообщение..';

                }
                else {
                    this.typing = null;
                }
            });

        let that = this;
        Echo.private('conv.'+this.convId)
             .listen('MessageIsSeen', (e) => {
                //if(e.message.user_id != this.user.userId)
                    $('li').removeClass('unread');
        });
    }
});

Message.vue:

<template>
    <li :class="className">
        <div class="row margin-left-none margin-right-none">
            <div class="col-md-2 padding-right-none">
                <div class="avatar-user text-center">
                        <img :src="user.avatar" alt="">
                </div>
            </div>

            <div class="col-md-10 padding-left-none">
                <div class="user-name">
                    <span>{{ user.name }} <i data-toggle="tooltip" title="Онлайн" class="material-icons online">fiber_manual_record</i> <span class="date float-right">{{ time }}</span></span>
                </div>
                <div class="message">{{ message }}</div>
            </div>
        </div>
     </li>
</template>

<script>
    export default {
        props: [
            'message',
            'user',
            'time',
            'seen',
        ],
        computed: {
            className() {
                return this.seen == 1 ? '' : 'unread';
            }
        },
        mounted() {
            //console.log(this.seen);
            console.log('Component mounted.')
        }
    }
</script>

Chat Controller:

public function setMessagesSeen(Message $message) {
        $user = Auth::user();
        $seen = $message->getNotification($user)->is_seen;
        if(!$seen)
            Chat::messages($message)->for($user)->markRead();
            broadcast(new MessageIsSeen($message));
 }

Event messageisseen:

<?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;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Musonza\Chat\Messages\Message;

use App\Models\User;
use Musonza\Chat\Conversations\Conversation;
use Chat;

class MessageIsSeen implements ShouldBroadcastNow
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $message;

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

        //$this->dontBroadcastToCurrentUser();
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('conv.' . $this->message->conversation_id);
    }
}

Chat blade:

<ul class="messages-list" style="height: 700px; overflow-y: auto" v-chat-scroll>
                @foreach($messages as $message)
                <li messageid="{{ $message->id }}">
                    <div class="row margin-left-none margin-right-none">
                        <div class="col-md-2 padding-right-none">
                            <div class="avatar-user text-center">
                                    <img src="{{ $message->sender->avatar }}" alt="$message->sender->name">
                            </div>
                        </div>

                        <div class="col-md-10 padding-left-none">
                            <div class="user-name">
                                <span>{{ $message->sender->name }}
                                    @if(Helper::getOnlineUser($message->sender->id))
                                    <i data-toggle="tooltip" title="Онлайн" class="material-icons online">fiber_manual_record</i>
                                    @else 
                                    <i data-toggle="tooltip" title="Оффлайн" class="material-icons offline">fiber_manual_record</i>
                                    @endif
                                    <span class="date float-right">{{ $message->created_at->diffForHumans() }}</span></span>
                            </div>
                            <div class="message">
                                {{ $message->body }}
                            </div>
                        </div>
                    </div>
                </li>
                @endforeach
                <message v-for="value,index in chat.message" 
                    :key=value.index 
                    :user=chat.user[index]
                    :message="chat.message[index]"
                    :messageId="chat.messageId[index]"
                    :time="chat.time[index]"
                    :seen="chat.seen[index]"
                >
                </message>
              </ul>
              <div class="send-message margin-bottom-1x">
                  <div class="panel-user">
                      <div class="pb-2 m-size-u float-left">
                          <div><strong>{{ $participant->name }}</strong></div>
                          <div><span class="text-muted" v-text="typing"></span></div>
                          <div>
                            @if(Helper::getOnlineUser($participant->id))
                                <span style="color: #0b0">Online</span>
                            @else
                                <span class="text-muted">Offline</span>
                            @endif
                          </div>
                      </div>
                  </div>
                  <div class="calc-text pb-2 float-right">
                      <span id="maxlengthmess">0</span>
                      <span>/ 4000</span>
                  </div>
                  <div class="form-group">
                    <textarea maxlength="4000" cols="80" rows="3" class="message-input form-control" v-model='message' v-on:click="seenMessage" onkeyup="calc_input_text(this)"></textarea>
                  </div>
                  <div class="form-group">
                      <button type="button" class="btn btn-lg btn-primary" v-on:click="send">Отправить сообщение</button>
                  </div>
              </div>

When I click on textarea, always send request to /setMessagesSeen , I can't think statement for this solution. I can't think logic. Please help. How I can do this system correctly?

1st March, 2018

Dronax left a reply on Laravel Migrate Error • 6 months ago

@blendpajaziti I don't need remove my data in mysql with migrate:refresh!!

Dronax left a reply on Laravel Migrate Error • 6 months ago

How I can ignore migrated migrations in folder database/migrations

Dronax started a new conversation Laravel Migrate • 6 months ago

Hello all. How I can migrate new migrations, not deleting used migrations?

Dronax left a reply on Correctly Mark Message Is Read • 6 months ago

Please help me!

27th February, 2018

Dronax left a reply on Correctly Mark Message Is Read • 6 months ago

@rumm.an when I click on textarea, I read message for all users. But if participant offline? This is not track. Problem: when sender click on textarea, he can read message and for participant. When I can prevent this?

Dronax left a reply on Correctly Mark Message Is Read • 6 months ago

Please Help!

25th February, 2018

Dronax left a reply on Correctly Mark Message Is Read • 6 months ago

@crnkovic I know echo, please read my question! I can't do read message correctly.

Dronax left a reply on Correctly Mark Message Is Read • 6 months ago

Please help!!!

Dronax started a new conversation Correctly Mark Message Is Read • 6 months ago

Hello all! Today is my birthday and I work on my project :)) Yes! I have a problem! Please help me fix message read event. He work not correctly.

<?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;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Musonza\Chat\Messages\Message;

use App\Models\User;
use Musonza\Chat\Conversations\Conversation;
use Chat;

class MessageIsSeen implements ShouldBroadcastNow
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $message;

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

        //$this->dontBroadcastToCurrentUser();
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('conv.' . $this->message->conversation->id);
    }
}

In controller:

    public function setMessagesSeen(Message $message) {
        $user = Auth::user()->id;
        //$message = Chat::messageById($message->id);
        //if($user != $message->user_id) {
            Chat::messages($message)->for($user)->markRead();
            broadcast(new MessageIsSeen($message));
        //}
    }

In app.js

methods: {
        seenMessage() { //this call when user click on textarea
            //console.log(this.chat.user);
            //if(this.chat.message.length != 0 && this.user.userId == this.chat.user.id) {
                axios.post('/setMessagesSeen/' + $('.messages-list > li:last').attr('messageid'))
                .then( response => {  }) 
                .catch( response => { console.log(response) } )
            //}
        },
        send(){
            if(this.message.length != 0 && this.message.length <= 4000) {
                this.chat.message.push(this.message);
                this.chat.user.push(this.user);
                this.chat.time.push(this.getTime());
                //this.chat.messageId.push('2131');
                this.chat.seen.push(0); //set message is readed. This add class "unread" to element
                axios.post('/sendMessage/' + this.convId, {
                    message: this.message,
                  })
                  .then(response => {
                    console.log(response);
                    this.message = '';
                  })
                  .catch(error => {
                    console.log(error);
                  });
            }
        },
        getTime() {
            let time = new Date();
            return time.getHours() + ':' + time.getMinutes();
        }
    },

munted() {
Echo.private('conv.'+this.convId)
             .listen('MessageIsSeen', (e) => {
                //if(e.message.user_id != this.user.userId)
                    $('li').removeClass('unread'); //class remove for all. But how Remove class when message is readed only?
        });
}

Channel:

Broadcast::channel('conv.{conv_id}', function($user, Conversation $conv_id) {
    return $conv_id->users->contains($user);
});

My problem: When 1 user send message to other user, current user can click on textarea and message mark read for all. How I can check correctly if message is seen for users?

24th February, 2018

Dronax started a new conversation How I Can Check User In Conversation In Channels.php ? • 6 months ago

Hello! I use package: https://github.com/musonza/chat#get-users-in-a-conversation

In channel.php I have:

Broadcast::channel('mc-chat-conversation.{conversation_id}', function($user, $conversation_id) {
    return $conversation_id->users->contains($user);
});

this is not working. How I can check correctly user in conversation channel?

Dronax left a reply on Event Not Listen On Private Channel.. • 6 months ago

Thanks :))

Dronax left a reply on Event Not Listen On Private Channel.. • 6 months ago

Problem in $user->id $this-> >?

Dronax left a reply on Event Not Listen On Private Channel.. • 6 months ago

I found problem :))

Dronax left a reply on Event Not Listen On Private Channel.. • 6 months ago

@rumm.an Yes. I can subscribe. But event not sending to pusher.

Dronax left a reply on Event Not Listen On Private Channel.. • 6 months ago

@rumm.an Done!

Dronax started a new conversation Event Not Listen On Private Channel.. • 6 months ago

Hello, I have event:

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

public $conversation;
public $user;

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

/**
 * Get the channels the event should broadcast on.
 *
 * @return \Illuminate\Broadcasting\Channel|array
 */
public function broadcastOn()
{
    return new PrivateChannel('conversation.'.$this->conversation->id.'.'.$user->id);
}}

In controller:

public function setMessagesSeen(Conversation $conversation) {

$user = User::find(Auth::id());

//$readed = Chat::conversations($conversation)->for($user)->readAll();

//if($readed)
broadcast(new MessageIsSeen($conversation, $user));

//return json_encode(['lol']);

}

In app.js

methods: { seenMessage() { //if(this.message.length != 0) { axios.post('/setMessagesSeen/' + this.convId) .then( response => { $('li').removeClass('unread'); }) .catch( response => { console.log(response) } ) //} }, //working. Send request to controller setMessageIsSeen mounted() { Echo.private('conversation.'+this.convId+'.'+ this.user.userId) .listen('MessageIsSeen', (e) => { console.log(e); }); }

Channel:

Broadcast::channel('conversation.{conversation_id}.{user_id}', function($user, $conversation_id, $user_id) { return $user; });

In mounted event not listen. In console I didn't have messages about event. In pusher I see messages only that channel: conversation.1.1 subscribed, occupied e.t.c. But messages about event MessageIsSeen - not. Please help fix it. In channels.php I have event.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.