kodyxgen

Software Engineer at UK

Member Since 4 Years Ago

Toplita

Experience Points
118,490
Total
Experience

1,510 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
1134
Lessons
Completed
Best Reply Awards
2
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 24
118,490 XP
Apr
19
3 weeks ago
Activity icon

Replied to Refactoring From Code Shared In Every Single Controller Method

I see that you are using the 'auth' middleware so users that can access that endpoint must be logged in https://laravel.com/docs/8.x/authentication#protecting-routes

will this not return true every time and if so why the need for it ?

 if ($user->id !== auth()->id()) {
            abort(403);
        }

or i didn't understand the question.

Activity icon

Awarded Best Reply on Grouping By And Then Getting First Of A Sub Group.

I don't know if this is what you want but take a look:

$usersPictures = collect([
    [
        'id' => 1,
        'user_id' => 1,
        'path' => '/s3/my_image_1.jpg',
        'group_id' => 'group_one'
    ],

    [
        'id' => 2,
        'user_id' => 1,
        'path' => '/s3/my_image_2.jpg',
        'group_id' => 'group_one'
    ],
    
    [
        'id' => 3,
        'user_id' => 1,
        'path' => '/s3/my_image_3.jpg',
        'group_id' => 'group_one'
    ],
    
    [
        'id' => 4,
        'user_id' => 1,
        'path' => '/s3/my_image_4.jpg',
        'group_id' => 'group_two'
    ],
    
    [
        'id' => 5,
        'user_id' => 1,
        'path' => '/s3/my_image_5.jpg',
        'group_id' => 'group_two'
    ]
    ]
);

$newCollection = $usersPictures->groupBy('group_id')->map(function($pictures,$index) {

		return $index = collect($pictures)->first();
        

});

and it will result in :

=> Illuminate\Support\Collection {#1161
     all: [
       "group_one" => [
         "id" => 1,
         "user_id" => 1,
         "path" => "/s3/my_image_1.jpg",
         "group_id" => "group_one",
       ],
       "group_two" => [
         "id" => 4,
         "user_id" => 1,
         "path" => "/s3/my_image_4.jpg",
         "group_id" => "group_two",
       ],
     ],
   }

See if it helps or gives you an idea.

Activity icon

Replied to Grouping By And Then Getting First Of A Sub Group.

I don't know if this is what you want but take a look:

$usersPictures = collect([
    [
        'id' => 1,
        'user_id' => 1,
        'path' => '/s3/my_image_1.jpg',
        'group_id' => 'group_one'
    ],

    [
        'id' => 2,
        'user_id' => 1,
        'path' => '/s3/my_image_2.jpg',
        'group_id' => 'group_one'
    ],
    
    [
        'id' => 3,
        'user_id' => 1,
        'path' => '/s3/my_image_3.jpg',
        'group_id' => 'group_one'
    ],
    
    [
        'id' => 4,
        'user_id' => 1,
        'path' => '/s3/my_image_4.jpg',
        'group_id' => 'group_two'
    ],
    
    [
        'id' => 5,
        'user_id' => 1,
        'path' => '/s3/my_image_5.jpg',
        'group_id' => 'group_two'
    ]
    ]
);

$newCollection = $usersPictures->groupBy('group_id')->map(function($pictures,$index) {

		return $index = collect($pictures)->first();
        

});

and it will result in :

=> Illuminate\Support\Collection {#1161
     all: [
       "group_one" => [
         "id" => 1,
         "user_id" => 1,
         "path" => "/s3/my_image_1.jpg",
         "group_id" => "group_one",
       ],
       "group_two" => [
         "id" => 4,
         "user_id" => 1,
         "path" => "/s3/my_image_4.jpg",
         "group_id" => "group_two",
       ],
     ],
   }

See if it helps or gives you an idea.

Apr
04
1 month ago
Activity icon

Replied to Assignment To AsArrayObject Casted Field Doesn't Work On A Null Value?

If you are using Mysql8.0.13+ you could do something like this

ALTER TABLE users modify COLUMN `config` JSON NOT NULL DEFAULT (JSON_OBJECT())

and you will have a default for the column config.

Apr
03
1 month ago
Activity icon

Replied to Multilingual Website Through Cookies Without Altering Url

You could try this plugin, maybe you get an inspiration.

https://github.com/mcamara/laravel-localization

I don't know if not adding the prefix language to the url is the best solution for SEO

Activity icon

Awarded Best Reply on How Can I Refactor This Code?

Hi, could something like this work for you ?

$sortedCities = $cities->groupBy(function($city,$id){

	return Str::limit($city,1,'');
        
}, true)->unique();
Activity icon

Replied to Laravel Firebase Not Sending Push

Could you try it like this:

$post_data = '{
        "registration_ids" : "' . $registration_ids . '",
        "data" : {
          "title" : "' . $title . '",
          "description" : "' . $message . '",
          "id" : "' . $id . '",
          "text" : "' . $message . '",
        },
        "notification" : {
			"content_available" : true,
             "mutable_content" : true,         
		    "body" : "' . $message . '",
            "title" : "' . $title . '",
            "description" : "' . $message . '",
            "sound" : "default"
            }

      }';

Activity icon

Replied to How Can I Refactor This Code?

Then maybe my first answer could the best one in your particular case ;)

Activity icon

Replied to How Can I Refactor This Code?

So you will use the Str::limit solution :)

Activity icon

Replied to How Can I Refactor This Code?

Performance

Activity icon

Replied to How Can I Refactor This Code?

I only could make it work if i reverted back to Str::limit - since there is a problem from the Cyrillic alphabet.

$cities = $cities->sort()->unique()
->groupBy(function (string $city): string {
	return strtolower(Str::limit(trim($city),1,''));
}, true);

and i get

=> Illuminate\Support\Collection {#1395
     all: [
       "Б" => Illuminate\Support\Collection {#1397
         all: [
           28 => "Бakersfield",
           2150 => "Бaltimore",
           4117 => "Бend",
           154 => "Бillings",
           1495 => "Бridgeport",
         ],
       },
       "Д" => Illuminate\Support\Collection {#1396
         all: [
           2713 => "Дbilene",
           1679 => "Дkron",
           18000 => "Дlexandria",
           24 => "Дntioch",
           1875 => "Дtlanta",
         ],
       },
     ],
   }

Activity icon

Replied to How Can I Refactor This Code?

Try adding true as a second argument for groupBy, that will return the id to.

Maybe best of all is :

$sortedCities = $cities->sort()->unique()
    ->groupBy(fn( string $city): string => strtolower(trim($city)[0]), true);

credits for @bugsysha for the array tip, he is right, it is better then Str::limit

Activity icon

Replied to How Can I Refactor This Code?

Yes you are right! in my first post i didn't add the collect(), after that i was not sure if pluck() is returning a collection or and array so i edited the post.

i will edit the post now so it will be correct.

Activity icon

Replied to How Can I Refactor This Code?

Or this, it is shorter.

$sortedCities = $cities->sort()->groupBy(
    fn($city) => Str::limit($city,1,''), true)->toArray();
Activity icon

Replied to How Can I Refactor This Code?

Hi, could something like this work for you ?

$sortedCities = $cities->groupBy(function($city,$id){

	return Str::limit($city,1,'');
        
}, true)->unique();
Activity icon

Replied to Laravel Collections: Do Something On The Collection

Hi, i maybe something like this ?

$collection = (is_array($collection) ? collect($collection)->first() : $collection)
    ->shuffle()
    ->take(5);