SPL3S

SPL3S

Member Since 1 Year Ago

Experience Points
3,230
Total
Experience

1,770 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
26
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.

Level 1
3,230 XP
Jul
29
1 week ago
Activity icon

Replied to Dislpay Only Unique Id's With The Sum Of Multiple Rows

@edoc why should I change table row names? isn't client_container_item .total_price being generated by relationship?

Activity icon

Replied to Dislpay Only Unique Id's With The Sum Of Multiple Rows

@edoc error is returned:

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'total_price' in field list is ambiguous (SQL: select SUM(total_price), `stock_id`, `client_container_item`.`client_id` as `pivot_client_id`, `client_container_item`.`container_item_id` as `pivot_container_item_id`, `client_container_item`.`created_at` as `pivot_created_at`, `client_container_item`.`updated_at` as `pivot_updated_at`, `client_container_item`.`stock_id` as `pivot_stock_id`, `client_container_item`.`pieces_total_quantity` as `pivot_pieces_total_quantity`, `client_container_item`.`total_price` as `pivot_total_price`, `client_container_item`.`total_cubic` as `pivot_total_cubic` from `container_items` inner join `client_container_item` on `container_items`.`id` = `client_container_item`.`container_item_id` where `client_container_item`.`client_id` = 1 group by `stock_id`)

Maybe I am trying to solve the issue from the wrong end, instead of storing every new container_item using attach:

 $containerItem->clients()->attach($client_id,
                ['stock_id' => request('stock_id'),
                'pieces_total_quantity' => $piecesTotalQuantity,
                'total_price' => $totalPrice,
                'total_cubic' => $totalCubic]);

I should update each entry with increment to increase the sum for each column. Still would be good to learn how to filter, sum and display for each model

Jul
28
1 week ago
Activity icon

Replied to Dislpay Only Unique Id's With The Sum Of Multiple Rows

Thanks for taking a look at it @edoc , I do get the array of each stock_id with total sum for each id in the table. But the issue now is that it sums up all the entries in the table, and I need to select stock_id's that are related to the client...

Illuminate\Support\Collection {#1264 ▼
  #items: array:3 [▼
    0 => {#1270 ▼
      +"SUM(total_price)": "2737.80"
      +"stock_id": 1
    }
    1 => {#1291 ▼
      +"SUM(total_price)": "336.31"
      +"stock_id": 2
    }
    2 => {#1310 ▼
      +"SUM(total_price)": "101.20"
      +"stock_id": 3
    }
  ]
}
Activity icon

Started a new Conversation Dislpay Only Unique Id's With The Sum Of Multiple Rows

I stumbled on the issue where I need to display each unique stock_id with the sum of some columns. A pivot table, where client and container items are stored with many-to-many method. And I can get all the pivot info for that client:

 @foreach($client->containerItems as $containerItem)
	{{ $containerItem->pivot->stock_id }}
	{{ $containerItem->pivot->pieces_total_quantity }}
	{{ $containerItem->pivot->total_cubic }}
 @endforeach

The issue is that I don't need to see every entry of the pivot table, but rather show only unique stock_id's together with the sum of all other same stock_id's. Here's the pivot table view: https://imgur.com/a/xbcH7X5

I can filter out only unique id's in controller:

$uniqueIds = $containerItems->unique('stock_id');

Then I should do foreach sum for each uniqueIds from the table?

foreach ($uniqueIds as $uniqueId) {
$sumTotalPrice = DB::table('client_container_item')
->where('stock_id', $uniqueIds)
->sum('total_price');
        }