SkyCoder

SkyCoder

Member Since 1 Year Ago

Experience Points
15,120
Total
Experience

4,880 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
60
Lessons
Completed
Best Reply Awards
1
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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.

Level 4
15,120 XP
Oct
29
2 weeks ago
Activity icon

Started a new Conversation Removing Duplicates From Mysql Table With Email Column

I have table with 20k rows that contains some emails and I would like to remove all duplicates.

I tried these:

delete from users using users, users e1 where users.id > e1.id and users.email = e1.email

DELETE FROM users WHERE id NOT IN (SELECT MIN(id) FROM users GROUP BY email)

DELETE e.*
FROM users e
WHERE id IN
 (SELECT id
   FROM (SELECT MIN(id) as id
          FROM users e2
          GROUP BY email
          HAVING COUNT(*) > 1) x);

None of these work, I still have duplicates...

Any ideas?

Oct
18
3 weeks ago
Activity icon

Started a new Conversation Is There A Way To Extend Env

Is there a way to extend env helper to accept param as env filename with env folder of env files? Case of usage:

I am creating package where I would like to give users full control with models, controllers... Like my package env and config have:

models>modelname>pathToModel::class routes>routeName>routePath etc...

Since config will publish automatically, if they update config will be new.. So I would like to have env file for only my package routes, middlewares, models etc..

So is there a way to make env folder and put env files within it. Where by using env helper to pass path to file for env reading

Oct
17
3 weeks ago
Activity icon

Replied to Extending Package.json Within Laravel Package

Well I am creating chat app that could be added to any projects that contains users table, with some additional tables. In that case I would do it with just components etc and then add it as option to use chat component if they want or just endpoints for custom frontend.

Oct
16
3 weeks ago
Activity icon

Started a new Conversation Extending Package.json Within Laravel Package

I am making some laravel package that would use vue.js, vuex and router. How can I include those from laravel package?

Do I need to change webpack.mix as well as app root package.json or is there some quicker way that doesn't require someone to manually install required packages?

Oct
14
4 weeks ago
Activity icon

Started a new Conversation How T Check Is Param Collection Or Object

I created custom notifications model with two params, notification and user/users. I tried to check if it is object or collection but it always returns as object.

public function send($notification, $users) {
        if(!is_null($users) && is_object($users)) {
          $this->create([
              'user_id' => $notification['user_id'],
              'foruser_id' => $users->id,
              'type_id' => $notification['type'],
              'info' => $notification['info'],
          ]);
        } else if(!empty($users)) {
            foreach($users as $user) {
                $this->create([
                    'user_id' => $notification['user_id'],
                    'foruser_id' => $user->id,
                    'type_id' => $notification['type'],
                    'info' => $notification['info'],
                ]);
            }
        }
    }

How can I check if I passed something like:

User::find($id) or User::where('id', '!=', auth()->user()->id)->get()

Sep
24
1 month ago
Activity icon

Started a new Conversation How To Handle Mass Mail Sending With Queue Timeout

I have table with 100K+ emails where I want to daily send some email:

I added schedule in app\Console\Kernel.php:

$schedule->job(new SendDailyEmails)->dailyAt('09:00');

Inside Job I have:

$users = User::all();
foreach($users as $user){
    Maill:to($user->email)->send(new DailyMail($user));
    $status = 'sent';
    if( in_array($user->email, Mail::failures()) ){
        $status = 'failed';
        Log::error($user->email . ' was not sent.');
    }else{
        Log::info($user->email . ' was sent.');
    }
    SentMail::create([
        'email' => $user->email,
        'status' => $status
    ]);
    
}

This works fine, but after some time this stops probably because job timeout. In failed_jobs table I get MaxAttemptsExceededException with message that Job attempted too many times or run too long. Since I set queue tries max to 3 within supervisor it should and do go 3 times only. And by testing things it did not try to attempt again because I got one mail instead of 3.

So it comes to timeout and I am not sure what is default value but does it matter since I will not know how much time it would take to send all emails?

Should I divide mails into groups of 50 and call separate job instances for each group?

Anyone have a good working answer for this?

Aug
12
3 months ago
Activity icon

Started a new Conversation Adding Custom Private Channel For Broadcasting Notification In Laravel

Broadcasting works but it uses notifiable_type as channel name with user id. But what if I want to change only on backend api that some model is within 10 sub folders. I would need to change that channel on frontend everywhere...

From docs I found this:

 /**
     * The channels the user receives notification broadcasts on.
     *
     * @return string
     */
    public function receivesBroadcastNotificationsOn()
    {
        return 'users.'.$this->id;
    }

But it is not working, it is still using notifiable_type as channel name.. How can I change this?

Aug
11
3 months ago
Activity icon

Replied to Watching For Div Width Changes In Vue

Yeah, I found this as minimal possible code package: https://github.com/Kelin2025/vue-responsive-components

Activity icon

Started a new Conversation Watching For Div Width Changes In Vue

I have an nuxt app where I have two sidebars, one on the left and one on the right.

Both are fixed and body has padding from right and left.

In the middle I have that loads pages.

Left sidebar can be minimized to 60px so I cannot use media queries for this and I need to watch for width changes, in case that width is < 500px I would add some other classes. Something like media queries for element instead of viewport.

Is there a way to do this without additional javascript libraries, plugins etc..?

Aug
07
3 months ago
Activity icon

Started a new Conversation How To Properly Use Api Auth With Passport

I am wondering is using auth()->user() usable with passport auth?

Currently I am using attempt method for login and on localhost I had no problem but on server I needed to add to use web instead of api to work with it. Now I am wondering is that right anyway?

Since I don't use session and cookies, when I send bearer token through headers does it directly check within database and then store User within auth()->user() or how does it work?

Aug
04
3 months ago
Activity icon

Started a new Conversation How To Properly Proxy Reverse Apache With Node

I am having nuxt and laravel combo, where I want to use domain-name.com for nuxt. Currently it is working domain-name.com:3000..

Aug
03
3 months ago
Activity icon

Started a new Conversation How To Install Latest Node And Npm On Centos 7

From every examples they use bash command and my brand new centos vps doesnt have bash command...

Jul
30
3 months ago
Activity icon

Replied to How Does Fill Update Work With Password Field

I understood you much clearer :D Will do it :D

Activity icon

Replied to How Does Fill Update Work With Password Field

It is for api, so I dont know how does that works with an api.. Also what if user is already logged in and he wants to change his password? I mean instead of checking for current password I can as well send code to email and then verify but that it different question from mine.

Like mine is validation for all fields for updating and then using all within fill or separately with example from up above :D

Activity icon

Started a new Conversation How Does Fill Update Work With Password Field

If I do

auth()->user()->fill([
  'password' => bcrypt(request('password'))
]);

It will make different hash and store new hash in database as new password since hashes won't match. I know this is not a big deal but should I still use fill or something like:

auth()->user()->password = request()->filled('password') && Hash::check(request('password'), auth()->user()->password) ? request('password') : auth()->user()->password ;
Jul
27
3 months ago
Activity icon

Replied to Get Users With Admin Role From Jeremykenedy/laravel-roles

Seems like I need to use something like this:

jeremykenedy\LaravelRoles\Models\Role::where('name, 'Admin')->first()->users()->has('posts')->get()

Activity icon

Started a new Conversation Get Users With Admin Role From Jeremykenedy/laravel-roles

User::whereHas('roles', function($q){
            $q->hasRole('Admin');
        })->has('posts')->get()

How can I check if rows have Admin role from jeremykenedy/laravel-roles package within query builder?

Activity icon

Started a new Conversation Get Users That Have One Post At Least

How would I get user that has at least one post:

SQL example:

SELECT u.* FROM USERS u WHERE EXISTS(SELECT NULL FROM posts p WHERE p.user_id = u.id)

Laravel resource example:

return [
    'user' => $this->when($this->posts->count(), [
        'name' => $this->name,
        'last_post' => $this->posts->last()
    ])
]

Laravel where exists example:

DB::table('users') ->whereExists(function ($query) { $query->select(DB::raw(1)) ->from('posts') ->whereRaw('post.user_id = users.id'); }) ->get();

Which one of these is better to use

Jul
24
3 months ago
Activity icon

Started a new Conversation When To Use Nuxtserverinit

I have schools page where I have 1500 schools that probably never change.

I want to on each school pages open, make request to api to check is school table updated. If it is I would change data within store and local storage and cookies.

I tried using asyncData() {} that needs to have return, but I am not returning any data but updating state if versions are not the same.

I looked up for nuxtserverinit but I am not sure how it works and when to use it?

Is there a better solution for this?

Jul
17
3 months ago
Activity icon

Replied to Laravel Queue:work Is Proccessing 10000 In 60s Until It Crashes

Well using redis-cli flushall and queue:work --tries=1 helped me clean all proceses that were stored within redis and fail after one try.

Activity icon

Started a new Conversation Laravel Queue:work Is Proccessing 10000 In 60s Until It Crashes

I don't know what exactly happened but when ever I start:

php artisan queue:work & redis-server.exe (windows)

I get a lot pf processings for 1 event even tho app is not used (opened on browser)

https://imgur.com/B71mDoM - Look at the picture

I am not even using this Event from picture....

I am so unsure why is this happening?

Jul
16
3 months ago
Activity icon

Replied to Socket IO Client Should Be Globally Available Error

I guess I found the way that works for unknown reason :D

import Echo from 'laravel-echo'
if (process.client) {
  window.io = require('socket.io-client')
}

And then

mounted() {
  let echo = new Echo({
    broadcaster: 'socket.io',
    host: 'http://seekers-backend.com:6001',
    auth: { headers: { Authorization: this.token } }
  })
  echo.private('user.' + this.$auth.user.id)
  .listen('MessageEvent', (e) => {
    // Do stuff
  })
}
Activity icon

Started a new Conversation Socket IO Client Should Be Globally Available Error

I am using nuxt/laravel api with laravel-echo-server and socket.io-client.

When I use it this way:

import Echo from 'laravel-echo'
if (process.client) {
  window.io = require('socket.io-client')
  window.Echo = new Echo({
     broadcaster: 'socket.io',
     host: 'http://seekers-backend.com:6001',
     auth: { headers: { Authorization: 'Bearer-token' } }
  })
}

And then use window.Echo.private().listen().... it works perfectly..

But when I try to declare it within data property I get error because that is rendered on server side... How can I use socket.io-client on server side rendering or how can I declare it on client side since I need access to getters for Bearer token.

Jul
15
3 months ago
Activity icon

Started a new Conversation Listening On Page Opens

Is there a way to listen on all domain based pages that are visited in laravel besides using third party websites and besides making custom url that redirects on different one on click and so on?

How does php artisan serve keeps the track of page opens?

Jul
07
4 months ago
Activity icon

Started a new Conversation Access Root State Or $auth From Module Getters In Vuex

I have root state which contains auth data from nuxt/auth..

Inside store/modules/messages/ I have also state and getters etc..

Inside getters I need to get auth data from root state but I dont know how..

I tried adding rootState to index.js from module:

import state from './state'
import rootState from '../../state'
import * as actions from './actions'
import * as mutations from './mutations'
import * as getters from './getters'

export default {
  namespaced: true,
  state,
  rootState,
  getters,
  mutations,
  actions
}

export const avatar = (rootState) => rootState.auth.user.avatar

But this still returns module state..

Jul
06
4 months ago
Activity icon

Started a new Conversation Nuxt Auth Request With Token Works But Custom Request Fails

I need to connect my client from nuxt to laravel api. Where I used nuxt/auth module and connected it to login/logout/mydata endpoints.

Logout and mydata require Bearer token and by default nuxt/auth module. Those requests work without problems. But when I want to add additional requests for lets say posts I use:

  async asyncData ({ app }) {
    let response = await axios.get('http://127.0.0.1:8000/api/posts', {}, 
    { headers: { 'Authorization': app.$auth.getToken('local'), 'Access-Control-Allow-Origin': '*' } }
    )
    return {
      posts: response.data
    }
  },

I always get 401 error as unauthorized. Even tho this work from POSTMAN and from auth module requests....

Jun
28
4 months ago
Activity icon

Replied to Leftjoin With Groupby Skips Groupby

@SNAPEY - I repaced that part within laravel query as well and I get same result

Activity icon

Replied to Leftjoin With Groupby Skips Groupby

@SNAPEY -

select COUNT(*) as newCount from `user` 
left join (select workout.user_id, workout.id_holofit from workout where workout.user_id > 1  group by workout.user_id) workout ON workout.user_id = user.id
where date(creation) between '2016-11-30' and '2019-06-28'

This is query that works as raw query.

Activity icon

Replied to Leftjoin With Groupby Skips Groupby

@SNAPEY - "try it including select for each column in your desired results" - i dont understand this could you give me an example

"also, what is $users before this query?" - Just

$users = User::whereBetween(
        DB::raw('date(creation)'), [
            $new_period->first()->format('Y-m-d'), 
            $new_period->last()->format('Y-m-d')
        ]);

And then I use $users->get();

Activity icon

Started a new Conversation Leftjoin With Groupby Skips Groupby

I have Users that I want to count by left joining table for workouts and getting one row for each user.

$users->leftJoin('workout', function($join){
                        $join->on('user.id', '=', 'workout.user_id')->where('workout.user_id', '>', 1)->groupBy('user.id')->orderBy('workout.id');
                })

First I dont get only one per workout, but for every workout. Like: w1 uid - 1 w2 uid - 2 w3 uid - 1

I get 3 users instead of 2...

Jun
15
4 months ago
Activity icon

Started a new Conversation Multi Relation Foreign Keys

If I have 3 tables:

User, Conversation, Messages

Between User and conversation I have:

$table->foreign('user_id')
                  ->references('id')
                  ->on('users')
                  ->onDelete('cascade');

And between conversation and messages:

$table->foreign('conversation_id')
                  ->references('id')
                  ->on('conversations')
                  ->onDelete('restrict');

If someone accidentally try to delete conversation, it should stop him because of messages restriction. But same way user is deleted I want to delete both conversation and messages.

How can I accomplish that?

Jun
13
4 months ago
Activity icon

Replied to How To Remove Port In Laravel Aap In Localhost In Ubuntu 16.04

@INDERSEIN - You can use lamp or something like that, because you probably wont let php artisan serve running as long as you want to use your website.

Activity icon

Replied to How To Display Data From Db Into Bar Chart

Well how do you think to add data.Verbal to array and get results when you have no data.Verbal key from your database, it is an value. Not column name

Activity icon

Replied to What Should I Use In Laravel For Onpage Add, Edit ,delete,view ,like,update In My Discussion Forum Platform?

@RAVIAWASTI - This is very complex thing to do, so listen carefully:

  1. Open up your browser
    • A web browser (commonly referred to as a browser) is a software application for accessing information on the World Wide Web. ... The most popular browsers are Chrome, Firefox, Safari, Internet Explorer, and Edge. (From wikipedia)
  2. Go to your search/url input and type https://www.google.com/
  3. When the site loads, use search box/input from under the Google logo.
  4. Type VueJS or VueJS documentation or even VueJS realtime update examples
Activity icon

Replied to Ideal Chat Migration

I don't think that I can remove receiver_id because:

If there is only user_id from sender, I would need to retrive receiver_id from conversation_id, could be something like conv-id = receiver_id-hash, where I would look for where receiver_id Like '%receiver_id-hash'.

But if you say its okay as it is, Ill keep using it.

Jun
12
5 months ago
Activity icon

Started a new Conversation Ideal Chat Migration

I was wondering is there an ideal migration structure for private chats between users.

I used something like:

user_id - as sender
receiver_id - as receiver
conversation_id - as id made by random hash with both user_id and receiver_id, created first time as someone sends a message
message - as message

Now to get list of messages I used that conversation_id as:

SELECT id, MAX(created_at) AS created_at, message, user_id, receiver_id, conversation_id FROM messages WHERE user_id = my_id OR receiver_id = my_id GROUP BY conversation_id

This outputs only last messages per conversation. Then to get messages I get it by conversation_id...

Is there a better way to do this?

May
28
5 months ago
Activity icon

Started a new Conversation Check Is Service Running Within Laravel

If I am using Laravel Scheduler and Laravel Echo Server.

$schedule->exec('laravel-echo-server start')
         ->everyMinute()
         ->onSuccess(function () {
             // send logs
         })
         ->onFailure(function () {
             // send failure message and retry
         });

Is there a way to check is laravel-echo-server active or down? I saw that I could use supervisor to auto-restart services etc. Is there a way to do it within laravel without supervisor or any other similar program?

May
23
5 months ago
Activity icon

Started a new Conversation Multiple OR's In Where Array

Is there a way to use this OR this OR this like with AND:

$query->where([ 
    [something 1],
    [something 2],
    [something 3],
]);

This is used like where something 1 AND something 2 .... Is there a way to use this for something 1 or something 2 ? Because I cannot know how many or's are there. Also I dont want old way by doing foreach and adding it to the string.

May
21
5 months ago
Activity icon

Started a new Conversation Laravel Groupby Multiple Columns And Merge

Is there an function to merge data from groupby with more columns?

$data->->groupBy('day','skill')->get();

and for output currently I have:

[day1,skill1], [day1, skill2], [day1, skill3], [day2, skill1]

Is there way to get:

[day1, [skill1, skill2, skill3]], [day2, [skill1]]

Without looping throught?

May
20
5 months ago
Activity icon

Started a new Conversation Laravel Group By Date Range

How can I group rows by custom daterange?

$new_period = CarbonPeriod::create($start, $end);

$data = (new Model)->whereBetween(DB::raw('date(start)'), [$new_period->first()->format('Y-m-d'), $new_period->last()->format('Y-m-d')])
 ->select(DB::raw('id, date(start) as day'))
 ->get()->groupBy('day');

This works but for each day that is not inside database but it is in $new_period range it gets skipped. I can do it with loops and create new collection or whatever. But I am wondering can I use something like:

->groupBy(['01/01/2019','02/01/2019','03/01/2019','04/01/2019','05/01/2019','06/01/2019','07/01/2019'])

By using carbonperiod