GGio

GGio

Member Since 4 Years Ago

Experience Points
35,870
Total
Experience

4,130 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
324
Lessons
Completed
Best Reply Awards
3
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.

Level 8
35,870 XP
Jul
06
6 days ago
Activity icon

Replied to Trait Naming Convention

Just pick one and follow that throughout your code. I personally use this https://github.com/alexeymezenin/laravel-best-practices & try to follow those conventions. As long as you stay consistent it should not really matter which convention you pick, its all about consistency.

Jun
28
2 weeks ago
Activity icon

Replied to Unit Testing Relationship Between Two Models

Instead of manually setting $user->team_id in addUser method. Using associate will set the relation properly

Activity icon

Replied to Unit Testing Relationship Between Two Models

I edited my answer explaining why

Activity icon

Awarded Best Reply on Unit Testing Relationship Between Two Models

Try adding $team->refresh() before assertContains.

Also I suggest setting relationship this way

$user->team()->associate($this)

The reason it fails if you uncomment the 4th line is because first time you load team members it has 0 members, next time you refer to the same relationship Laravel doesn't load from database anymore but loads from memory. Because Laravel already loaded this relationship in memory with 0 members, it simply gives you that result back and therefore your test fails.

Adding refresh should reload the relationship.

Activity icon

Replied to Unit Testing Relationship Between Two Models

Try adding $team->refresh() before assertContains.

Also I suggest setting relationship this way

$user->team()->associate($this)

The reason it fails if you uncomment the 4th line is because first time you load team members it has 0 members, next time you refer to the same relationship Laravel doesn't load from database anymore but loads from memory. Because Laravel already loaded this relationship in memory with 0 members, it simply gives you that result back and therefore your test fails.

Adding refresh should reload the relationship.

Jun
01
1 month ago
Activity icon

Replied to How To Create Duplicate Of A Laravel Collection

I suggest not doing raw SQL queries like that. Either use eloquent or build your queries as @tray2 has suggested in his second example.

But since you already have a relationship & have access to the $tournament, you could also use eloquent & build your query from $tournament->tournamentResult()->where('date', $resultDate)->...

May
30
1 month ago
Activity icon

Replied to How To Create Duplicate Of A Laravel Collection

@chesterbot have you tried my suggestion? With my suggestion, you don't need forget

May
29
1 month ago
Activity icon

Replied to How To Create Duplicate Of A Laravel Collection

If I understand correctly, you are trying to sum the tournament results for each player, but because playerResults is a very large collection you are removing the items that you already checked. I think the main problem is that you are loading all the tournamentResult records and applying where after, on a large collection.

This line:

$playerResult = $tournament->tournamentResult->where('player_id', $player->id)->where('date', $resultDate);

hydrates all tournamentResult records and then applies where to the collection that can contain hundreds or thousands of records already loaded. You can optimize it to this:

foreach($tournament->players as $player) {
    $result[$player->id] = $tournament
    ->tournamentResult()
    ->where('player_id', $player->id)
    ->where('date', $resultDate)
    ->sum('total_runs');
}

where is applied on query builder before the data is queried & loaded, so you don't need to run forget after because this will only load the records that it needs and not everything.

May
21
1 month ago
Activity icon

Replied to Eloquent Relationship, Group By

Are you trying to do group by in a query or on an existing collection?

Please add some more details on what you are trying to do. Using group by on an existing collection works fine unless it's not what you are looking for:


$arr = [
    [
        'id' => 1, 
        'university_id' => 1, 
        'program_name' => 'Business School',
        'created_at' => '2020-03-18 06:25:50', 
        'updated_at' => '2020-03-18 06:25:50', 
        'course' => [],
    ],    
    [
        'id' => 2, 
        'university_id' => 2, 
        'program_name' => 'Business School',
        'created_at' => '2020-03-18 06:25:54', 
        'updated_at' => '2020-03-18 06:25:54', 
        'course' => [],
    ],    
    [
        'id' => 3, 
        'university_id' => 3, 
        'program_name' => 'Business School',
        'created_at' => '2020-03-18 06:26:00', 
        'updated_at' => '2020-03-18 06:26:00', 
        'course' => ["cours1", "course2"],
    ],    
];

dd(collect($arr)->groupBy('program_name'));
May
18
1 month ago
Activity icon

Replied to Should I Always Develop "locally"

Using valet or homestead does not mean you are in production, you are still developing locally.

Valet is great for mac as far as I know. I personally have not used it because I'm on Ubuntu. I use docker for local development, makes it easier to work on multiple projects that require different versions of dependencies such as PHP, MySQL, Redis, etc.

If you have time, I suggest looking into docker & docker-compose.

Activity icon

Awarded Best Reply on Distant Relationship Problem

Seems like vcpu is a pivot table so you should use belongsToMany for both relationships https://laravel.com/docs/7.x/eloquent-relationships#many-to-many

Activity icon

Replied to Distant Relationship Problem

Seems like vcpu is a pivot table so you should use belongsToMany for both relationships https://laravel.com/docs/7.x/eloquent-relationships#many-to-many

Mar
20
3 months ago
Activity icon

Replied to Validation Of Many Fields

I think you are trying to optimize before you've written the code. Write the code first all 7 lines for the validation or however many you need, get it working first, add some tests. Then look for optimizations if needed.

Don't need to overcomplicate it.

Mar
17
3 months ago
Activity icon

Replied to Show Old Values In Edit Form For Checkbox And Select

You need to set checkbox checked & drop-down option as selected.

Something like:

<option value="{{ $author->id }}" {{ $book->author->id === $author->id ? 'selected' : '' }}>{{ $author->name }}</option>

and for checkbox:

<input type="checkbox" name="genres[]" value="{{ $genre->id }}" {{ $book->genre->id === $genre->id ? 'checked' : '' }}>

Activity icon

Replied to Help Wanted For Migration

Agree with @bobbybouwmann .

What if you simply moved shop_id column from ProductPurchaseOrder to PurchaseOrders assuming that each purchase order would be associated with a specific shop, that should simplify things a bit.

If you can have products from multiple shops in a single purchase order then what @bobbybouwmann suggested having products to shops table makes more sense.

Mar
13
3 months ago
Activity icon

Replied to Mocking A Trait

You could just use the trait within your test class like this:

class FilterByStartDateTest extends TestCase
{
   use FiltersByStartDate;

   private $builder;

   public function some_models_can_be_filtered_by_their_start_date()
   {
        $this->markTestIncomplete();

        $dateSet = ['2020-01-01 00:00:00'];

	$this->builder = \Mockery::mock(Builder::class)
            ->shouldReceive('whereBetween')
            ->withArgs(['started_at', $dateSet])
            ->once()
            ->andReturn(true)
            ->getMock();

        $this->assertSame($this->startedAt($dateSet), $this->builder);
   }
}

Haven't tested but it should work I think

Mar
12
4 months ago
Activity icon

Replied to I've Questions About Eloquent Relationships

Not sure I fully understand the concept here but this may help you:

For worker_lines table, you will need worker_id, line_id as a unique key

Mar
11
4 months ago
Activity icon

Replied to A Medium Sized Personal Project

You should build something that you will have fun working on. If you are not into blogs/forums/todo lists etc, it will be boring & you will most likely give up on it as it becomes more complex.

My advice is that you think about what apps/software you really like that you use on a daily basis. For example, do you use a budgeting app like mint? If yes maybe try to build your own custom budgeting app. Do you like working with CRM services like Zoho? Build a mini custom CRM.

I like to work with payments & payment integrations, so I decided to work on Invoicing/Billing system for my side project.

At the end of the day, you are not getting paid for the project that you will be building, at least not yet. You should have as much fun as possible while working on it.

Mar
10
4 months ago
Activity icon

Replied to Function Not Defined

try including it as <script src="{{ mix('js/app.js') }}"></script>

but I think the issue here is with the scope. Your function defined in app.js is not in the global scope after it is processed by Webpack. In general it is not good idea to use functions such way. The best way is to define them in specific files & include that js file in your blade. I am not JS expert so not sure if there is a better way but I would suggest assigning id/class to the button & define on click event handler in JS.

Activity icon

Replied to Function Not Defined

where is your app.js loaded from, try putting it at the end of <body>

Activity icon

Replied to How Can I Ignore Data That Equal With Another Field ?

Try

$profitLoss = Stock::whereColumn('profit', '!=', 'loss')->orderBy('profit', 'desc')->orderBy('loss', 'desc')->get();

That should give u all results where profit & loss don't equal to each other sorted by profit first & then by loss.

If you really just want the single highest profit row and single highest loss row then use these:

$profit_stocks = Stock::where('profit','>','0')->orderBy('profit','desc')->first();
$loss_stocks   = Stock::where('loss','>','0')->orderBy('loss','desc')->first();
Activity icon

Replied to How Can I Ignore Data That Equal With Another Field ?

What is the business logic behind it? Are you trying to get a single profit row the highest one?

Activity icon

Replied to How Can I Ignore Data That Equal With Another Field ?

When lines become too long I tend to put them on new lines, it's more readable. On your example, you have too much space though, if you are using editor like phpstorm it should align it correctly if spacing settings are set.

Activity icon

Replied to What To Name These Tests?

You should be able to understand what the test is about and what it is testing by just reading its name. For example:

dont_update_if_user_doesnt_have_access_author_dashboard_permission can be changed to it_doesnt_update_post_when_user_is_not_authorized_to_access

dont_update_if_user_is_unauthorized can be changed to it_doesnt_update_post_when_user_doesnt_have_proper_permissions

Activity icon

Awarded Best Reply on How Can I Ignore Data That Equal With Another Field ?

I think you can simply ignore the records where loss is 0 for the profit stocks & where profit is 0 for loss stocks:

$profit_stocks  = Stock::where('profit','>','0')
                         ->where('loss', 0)
                         ->orderBy('profit','desc')
                         ->get();


$loss_stocks    = Stock::where('loss','>','0')
                         ->where('profit', 0)
                         ->orderBy('loss','desc')
                         ->get();

If you can post more details on what exactly the end goal is, I might be able to help you better.

Activity icon

Replied to How Can I Ignore Data That Equal With Another Field ?

I updated my answer. Take a look.

Activity icon

Replied to How Can I Ignore Data That Equal With Another Field ?

I think you can simply ignore the records where loss is 0 for the profit stocks & where profit is 0 for loss stocks:

$profit_stocks  = Stock::where('profit','>','0')
                         ->where('loss', 0)
                         ->orderBy('profit','desc')
                         ->get();


$loss_stocks    = Stock::where('loss','>','0')
                         ->where('profit', 0)
                         ->orderBy('loss','desc')
                         ->get();

If you can post more details on what exactly the end goal is, I might be able to help you better.

Activity icon

Started a new Conversation Do You Unit Test Every Single Function Of The Class?

I am starting to get into a habit of writing a lot more tests for my projects than I did before. It feels somewhat redundant sometimes when I write a unit test for every single function of the class, but on the other hand, it gives me more confidence in having these tests even if they are redundant. Take this class for example:

class Foo {
    public function bar() { ... $this->baz(); $this->qux(); ... }

    public function baz() { ... }

    public function qux() { ... }
}

I write a unit test for bar, baz and qux. If bar test also touches & tests baz and qux is it redundant to have separate tests for baz/qux? When do you decide that you got enough coverage for the class and other "helper" methods don't really need their own tests?

I was watching Jeffrey`s Code Katas episode where he omits tests for helper methods when refactored, but those are technically covered in the main test that he wrote.

Feb
03
5 months ago
Activity icon

Replied to CC/BCC Does Not Work When Set Inside Mail Class

Nevermind, looks like its working, I was relying too much on the telescope, when previewing the mail there it did not show cc/bcc but then I downloaded the .eml file and it shows in the raw .eml file. Thanks guys.

Activity icon

Replied to CC/BCC Does Not Work When Set Inside Mail Class

I am returning $this->html(): return $this->html($htmlContent)

Laravel version I am using is 6.13.1

Activity icon

Replied to CC/BCC Does Not Work When Set Inside Mail Class

What if I have multiple emails that need to be added in cc/bcc? I think it should work without returning it. I tried your example and still doesn't work.

Jan
31
5 months ago
Activity icon

Started a new Conversation CC/BCC Does Not Work When Set Inside Mail Class

Hey guys,

I am having trouble with Mail classes. I am trying to set cc & bcc within the Mail class but it does not seem to work:

public function build() {
   ...
   $this->cc('[email protected]', 'Foo Bar')
   $this->bcc('[email protected]', 'Foo Bar')
   ...
}

Above does not work. I know Mail::to()->bcc()->cc() would work but in my case, I need to set the cc/bcc within the Mail class, is there something I am missing?