Stank0V01

IplexMC at IplexMC

Member Since 2 Years Ago

Vratsa Bulgaria

Experience Points
4,590
Total
Experience

410 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
19
Lessons
Completed
Best Reply Awards
1
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    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.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 1
4,590 XP
Mar
30
1 month ago
Activity icon

Started a new Conversation Custom Type Of Tenancy Setup.

Hello guys.

Im beginning directly with the question. Im trying to do something like tenancy but based on "building" and not on domain and etc.

I must have multiple databases with same schema structure (I've already have system migrations and migrations that are the same for all of the other databases)

My system schema is something like that:

Offices
     - id
     - name
     - description
     - district_uuid

Districts:
     - id
     - uuid (string)
     - db_name

And my others not system migration have relationship to offices

Example not system table

- column1
- column2
- office_id

The thing i want to do is, when i make create,delete,insert,find etc. To be in correct district database. I've tried with trait but I had an issue to get office_id and by that to find the district db name. Is there any way to do that?

(The database names are generated dynamically) I set the config db name by config()->set().

Mar
25
1 month ago
Activity icon

Awarded Best Reply on Laravel Echo, Not Listening On Events

I fixed it. It was not from any of those issues. I just downgrade my socketio-client to version 2.4.0 and it's work like it supposed to.

Thank you for the fast responses, @brvk.

I saw it on that github issue:

https://github.com/tlaverdure/laravel-echo-server/issues/550

Activity icon

Replied to Laravel Echo, Not Listening On Events

I fixed it. It was not from any of those issues. I just downgrade my socketio-client to version 2.4.0 and it's work like it supposed to.

Thank you for the fast responses, @brvk.

I saw it on that github issue:

https://github.com/tlaverdure/laravel-echo-server/issues/550

Activity icon

Replied to Laravel Echo, Not Listening On Events

Still don't work. I'm struggling of that for 2 days .

Activity icon

Replied to Laravel Echo, Not Listening On Events

Did I need to run queue:work command after that? I change the interface to ShouldBroadcastNow but still don't work :/

Activity icon

Replied to Laravel Echo, Not Listening On Events

Ive tried that and still don't work.

Mar
24
1 month ago
Activity icon

Started a new Conversation Laravel Echo, Not Listening On Events

Hello guys, so I'm trying to listen for event on my channel but it doesn't work for some reason.

Here is my Event:

<?php

namespace App\Events;

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

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

    public $message;

    public function __construct($message)
    {
        $this->message = $message;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('test');
    }

    /**
     * @return string
     */
    public function broadcastAs()
    {
        return 'TestEvent';
    }
}

And I broadcasted it with broadcast helper on my route (web.php)

Route::get('/socketTest', function () {
    if (broadcast(new \App\Events\TestEvent('hello'))) {
        return 'ok';
    }
});

Everything here work fine the event is sended to queue:work and in laravel-echo-server is displayed like following:


⚠ Starting server in DEV mode...

✔  Running at 127.0.0.1 on port 6001
✔  Channels are ready.
✔  Listening for http events...
✔  Listening for redis events...

Server ready!

Channel: apps_database_test
Event: TestEvent

My .env variables:

BROADCAST_DRIVER=redis
CACHE_DRIVER=redis
QUEUE_CONNECTION=redis
SESSION_DRIVER=redis
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

Everything on redis is fine, i mean connection,data saving etc.

But on a frontend side when I try to listen for the event nothing happens. I use VueJS with Laravel Echo library.

My main.js:

import Vue from 'vue'
import App from './App.vue'
import Echo from "laravel-echo";


Vue.config.productionTip = false

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

const EchoInstance = new Echo({
    broadcaster: 'socket.io',
    host: '127.0.0.1:6001',
});

window.Echo = EchoInstance;

new Vue({
    render: h => h(App),
}).$mount('#app')

And my App.vue

<template>
  <div id="app">
    <img alt="Vue logo" src="./assets/logo.png">
    <HelloWorld/>
  </div>
</template>

<script>
import HelloWorld from './components/HelloWorld.vue'

export default {
  name: 'App',
  components: {
    HelloWorld
  },
  mounted() {
    window.Echo.channel('test').listen('TestEvent', (data) => {
      console.log(data);
    })
  }
}
</script>

What I've done wrong? Please help me thanks. :)

Mar
19
1 month ago
Activity icon

Replied to Authentication Helper Not Work In The Model.

I just override this model function

   protected function asDateTime($value)
    {
        $timezone = auth()->check() ? auth()->user()->school->timezone : config('app.timezone');
        dd(auth()->check());
        //
        // any Carbon instance is going to be translated to UTC before saving
        //
        if ($value instanceof Carbon) {
            $value->timezone(config('app.timezone'));
        }

        // Any datetime or carbon instance is going to be translated to authenticated user timezone.
        if ($value instanceof DateTimeInterface) {
            return dd(new Carbon(
                $value->format('Y-m-d H:i:s'),
                $timezone
            ));
        }

        return parent::asDateTime($value);
    }

I call the model from the controller.

Activity icon

Started a new Conversation Authentication Helper Not Work In The Model.

Hello Guys. So I'm trying to use authenticatable helper auth() in the model but it's not work like I expected. auth()->check() returns false, and the auth()->user() is null.

Does anyone have any idea why this is happening? Thanks.

Mar
18
1 month ago
Activity icon

Replied to How To Make Laravel Save All Input Dates In Default Timezone.

So the request will be something like that

2021-03-17 15:36

I have timezone of the users in users table.

Activity icon

Replied to How To Make Laravel Save All Input Dates In Default Timezone.

So I have an app that users select a date for creating a building schedule (Every building has his own timezone). I want everything user save from dates input to be in default timezone, because i have many schedulers that check for daily recurrences.

Activity icon

Started a new Conversation How To Make Laravel Save All Input Dates In Default Timezone.

Hello. I'm trying to save all of the input dates in request to be in default UTC timestamp before saving.

I've seen tutorial back in time that will make the work with that in the model:

    /**
     * @param mixed $value
     * @return false|\Illuminate\Support\Carbon
     */
    protected function asDateTime($value)
    {
        if ($value instanceof Carbon) {
            $value->timezone(config('app.timezone'));
        }

        return parent::asDateTime($value);
    }

But I don't think this is the right way to do it. Is there any other good way of do that? Thanks.

Activity icon

Started a new Conversation Current Time-zone For Carbon On Many Records.

Hello guys. So i'm trying to set correct time-zone on Carbon::today() for getting all of the results created for this day. Let's explain a little bit more.

I have a command that archive the Notes when created_at column is today, so I get all Notes that are created today and check them in foreach based on Building model timezone

Database structure:

Buildings:
	-id
	-name
	-timezone

Notes:
	-id
	-name
	-created_at
	-updated_at
	-building_id (reference id on buildings)

My code:

$notes = Note::where('archived', null)
		->whereDate('created_at',Carbon::today())
		->get();


foreach($notes as $note) {
	// Set the current timezone 
	date_default_timezone_set($note->building->timezone)

	$note->update([
		'archived' =>1,
		'archived_at'=>Carbon::now()
	]) // update archive status etc...
}

I want Carbon::today() to be with the current timezone of the record building.

I've tried with that query too:

select
    *
from
    `notes`
    inner join `buildings` on `notes`.`building_id` = `buildings`.`id`
where
    date(`notes`.`created_at`) = CONVERT_TZ('NOW()', 'UTC', `building`.`timezone`);

Is there any way to do that? Thanks. :)

Feb
09
2 months ago
Activity icon

Started a new Conversation Laravel: Multiple Morph Relationship

Hello guys. So let's begin with the question, i have a database with the following structure:

walks:

id | from_user_id | to_user_id | from_room_id | to_room_id |
1          0               4      1              0
2          1               0      0              1
3          1               2      0              0

So the main thing, I've tried to do is when the user is creating a Walk pass he can choose from dropdown User or Room that he starting to walk.

How the cases looks?:

- from User to Room
- from Room to User
- from User to User

If from the first dropdown is selected room the from_user_id will be 0, and it's same on the second dropdown If from the second dropdown is selected user to_room_id will be 0.

So i choose to use laravel morphs but I'm not sure how to do that properly.

I have Room,User and Walks models.

In the Walks.php model i have something that it looks like that:

    /**
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
     */
    public function from()
    {
        return $this->morphTo();
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
     */
    public function to()
    {
        return $this->morphTo();
    }

Room model:

    /**
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
     */
    public function fromWalk()
    {
        return $this->morphMany(Walk::class, 'from');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
     */
    public function toWalk()
    {
        return $this->morphMany(Walk::class, 'to');
    }

User model:

    /**
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
     */
    public function fromWalk()
    {
        return $this->morphMany(Walk::class, 'from');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
     */
    public function toWalk()
    {
        return $this->morphMany(Walk::class, 'to');
    }

Did i need a following columns?

from_type
to_type

and how I'll be able to store that in the controller then in database?

Feb
01
3 months ago
Activity icon

Replied to Laravel Collections: Filter With Two Cloumns

Is there any other way to do that without using selectRaw or DB::raw after getting the results as an array ?

Activity icon

Replied to Laravel Collections: Filter With Two Cloumns

I just want to get the records from database

pluck() the first_student_id and second_student_id and find the expected output above from the question.

Activity icon

Started a new Conversation Laravel Collections: Filter With Two Cloumns

So let's just begin with the question.

I have a database with following structure:

id first_user_id  second_user_id
                                                    
1       1           2             
1       2           4			  
1       2           1             

And let's say i have a variable with id=1 $id = 1

I find the needed records with this.

Model::where('status',1)
->where('first_user_id', $id)
->orWhere('second_user_id',$id)->get();

I want to get all of the ids that is not equals to the $id in some of the columns.

For exampe:

if first_user_id is equals to $id
    return second_user_id column
if second_user_id is equals to $id
    return first_user_id column

I want to done that with Laravel Collections if it is possible?

The result must be array with the ids from condition above.

Example output:

Array
(
    [0] => 2 // second_user_id from first record
    [1] => 2 // first_user_id from the last record.
)

For more clearly here is some pseudo php code for what i exactly want

<?php

$students = [
  [
    "first_user_id" => 1,
    "second_user_id" => 2
  ],
    [
    "first_user_id" => 2,
    "second_user_id" => 3
  ],
    [
    "first_user_id" => 1,
    "second_user_id" => 3
  ],
    [
    "first_user_id" => 4,
    "second_user_id" => 6
  ],
];


$var = 2; // Authenticated user
$arr = [];
foreach($students as $student) {
  if($student['first_user_id'] == $var || $student['second_user_id'] == $var) {
    if($student['first_user_id'] == $var) {
      $arr[] = $student['second_user_id'];
    } else $arr[] = $student['first_user_id'];
  }
}

print_r($arr);

Output:

Array
(
    [0] => 1
    [1] => 3
)

Thank you.