Nospoon

Member Since 6 Years Ago

Experience Points
20,555
Total
Experience

4,445 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
323
Lessons
Completed
Best Reply Awards
0
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 5
20,555 XP
Jun
09
3 days ago
Activity icon

Replied to Order Records By Relation's Average Value

Yes, but I can just access the simCard relation on the call. And because they are grouped by the sim_card_id, I only get one Call per SimCard. When doing it the other way around it was returning weird values.

Activity icon

Awarded Best Reply on Order Records By Relation's Average Value

Managed to get it working with just a slight alteration by adding select('*'). So here's the working setup:

$longestCalls = Call::with(['simCard'])
            ->select('*')
            ->whereDate('start_time', '>=', $rangeStart)
            ->groupBy('sim_card_id')
            ->selectSub('avg(total_length)', 'average_length')
            ->orderBy('average_length', 'desc')
            ->limit(10)
            ->get();

With the addition of that select * it now properly hydrates all attributes and relations. I'm still a bit puzzled though why it behaves like this.

Activity icon

Replied to Order Records By Relation's Average Value

I did try that as well. It seemed to work on the first glance, but I quickly realised the average values were incorrect.

Activity icon

Replied to Order Records By Relation's Average Value

Managed to get it working with just a slight alteration by adding select('*'). So here's the working setup:

$longestCalls = Call::with(['simCard'])
            ->select('*')
            ->whereDate('start_time', '>=', $rangeStart)
            ->groupBy('sim_card_id')
            ->selectSub('avg(total_length)', 'average_length')
            ->orderBy('average_length', 'desc')
            ->limit(10)
            ->get();

With the addition of that select * it now properly hydrates all attributes and relations. I'm still a bit puzzled though why it behaves like this.

Activity icon

Started a new Conversation Order Records By Relation's Average Value

I have two related entities, SimCard and Call, SimCard has many Calls. The Call entity has a total_length attribute. I need to grab top 10 SimCards, whose related Call records from the last month have the the highest average total_length. Is this possible at all using Eloquent? So far I've had no luck getting this to work.

I could get the average part working (kind of...) using selectSub():

$longestCalls = Call::with('simCard')
            ->whereDate('start_time', '>=', $rangeStart)
            ->groupBy('sim_card_id')
            ->selectSub('avg(total_length)', 'average_length')
            ->orderBy('average_length', 'desc')
            ->limit(10)
            ->get();

However when I do this, the resulting objects contain only one attribute, the average_length, no other attributes are hydrated.

May
24
2 weeks ago
Activity icon

Replied to Factory Reusing The Same Data On Each Iteration

Turns out it was my mistake. The seeder calls were set up in wrong order, in turn at the time when the CallSeeder was run there was actually only 1 record matching the criteria...

May
21
3 weeks ago
Activity icon

Started a new Conversation Factory Reusing The Same Data On Each Iteration

I'm having an issue when trying to seed test data using model factory. I'm using existing database records populated by other seeders to make sure I'm using valid relationships. The expected result is that on each iteration it should grab a new SimCard record from database and use that to populate the Call attributes, what happens though is that it grabs a record once and uses it for all 200 iterations. I guess it has to do with how the factories work, but is there any way around this? I also tried moving the data generation logic from factory to seeder, but with the same result.

CallFactory

public function definition()
{
    $sim = SimCard::whereHas('inboundNumber')
        ->whereHas('alarmCentre')
        ->inRandomOrder()
        ->first();

    return [
        'caller_id' => $sim->msisdn,
        'destination' => $sim->inboundNumber->number,
        'alarm_centre_id' => $sim->alarm_centre_id,
        'sim_card_id' => $sim->id,
    ];
}

CallSeeder

Call::factory(200)->create();
May
12
1 month ago
Activity icon

Replied to Can't Change Default Pagination View

I also tried explicitly specifying the view in AppServiceProvider's boot mehtod as per documentation, that doesn't work either.

Paginator::defaultView(resource_path('views/vendor/pagination/tailwind.blade.php'));
May
07
1 month ago
Activity icon

Started a new Conversation Wire:click.self Not Working Correctly In Child Component

I have a Livewire component user-index which renders a user-element child component for each user entity. The child component contains a modal and a link to open it and perform an action.

// user-index.blade.php

@foreach($users as $user)
    <livewire:user-element :user="$user" :wire:key="$user->id">
@endforeach
// user-element.blade.php

<x-jet-dropdown-link href="#" wire:click.self.prevent="openModal">
     Make Admin
</x-jet-dropdown-link>

...

<x-jet-confirmation-modal wire:model="confirmAdminModal">
    <x-slot name="title">Please Confirm</x-slot>
    <x-slot name="content">Confirm changing admin permissions for {{ $user->name }}</x-slot>
    <x-slot name="footer">
        <x-jet-button wire:click.self="changeAdmin">Confirm</x-jet-button>
        <x-jet-button wire:click.self="closeModal">Cancel</x-jet-button>
    </x-slot>
</x-jet-confirmation-modal>

However despite using the .self directive, when the button is clicked, it keeps triggering the actions on the wrong component. Whenever a method is invoked, it tries to call it on the parent component instead of current one, which causes a "public method not found" error.

Activity icon

Started a new Conversation Can't Change Default Pagination View

I'm trying to make a small change to the default pagination component. Followed the documentation, after publishing the vendor views with php artisah vendor:publish --tag=laravel-pagination I modified the tailwind.blade.php file, but the changes are not being applied, no matter how many times I clear the cache and reload the browser, it still doesn't seems to use the default component rather than the published one. Any ideas why could this be?

Mar
23
2 months ago
Activity icon

Started a new Conversation Laravel Sail Shutting Itself Down

I have Sail installed on a fresh project. If I run sail up -d it starts up fine. However if I try to run any command on it, like sail artisan migrate, I get the following output:

Shutting down old Sail processes...
Sail is not running.

So it basically stops itself and then complains that it did...

I'm on OSX, in case it matters.

Mar
22
2 months ago
Activity icon

Replied to Detach Child Relation From Parent Without Deleting

I was hoping there was a way to avoid doing it backwards like that. I guess there's not then.

Activity icon

Started a new Conversation Detach Child Relation From Parent Without Deleting

I have the following model structure:

class Device extends Model
{
    public function simCards()
    {
        return $this->hasMany(SimCard::class);
    }

    public function primarySimCard()
    {
        return $this->hasOne(SimCard::class)->where('primary', true);
    }

    public function secondarySimCard()
    {
        return $this->hasOne(SimCard::class)->where('primary', false);
    }
}
class SimCard extends Model
{
    public function device()
    {
        return $this->belongsTo(Device::class);
    }
}

I'm using a nested resource route for assigning SimCards to Devices, so I have a DeviceSimCardController which takes primary_sim_card and secondary_sim_card as json arguments. The assignment part works fine, but what I'd like to happen is, if for example if I send a request wheresecondary_sim_card is set to null, I want the binding to be removed if it already exists.

So I want something like$device->primarySimCard()->detach(), but that won't work.

My controller code looks something like this:

if ($request->has('secondary_sim_card')) {
    $secondarySim = $request->get('secondary_sim_card');

    if ($secondarySim === null && $device->secondarySimCard()->exists()) {
        // Detach the related SimCard from the device
    } else {
        $secondarySim = SimCard::findOrFail($secondarySim['id']);
        $secondarySim->primary = false;
         $device->secondarySimCard()->save($secondarySim);
   }
}