nategg

nategg

Member Since 7 Months Ago

Experience Points
12,730
Total
Experience

2,270 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
120
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 3
12,730 XP
Aug
02
1 week ago
Activity icon

Replied to 1146 Error Shows Column Name As The Table Name, Says It Doesn't Exist

Thanks that did the trick, except seems I needed a comma after the first round_id. I really appreciate your help.

Jul
31
1 week ago
Activity icon

Replied to 1146 Error Shows Column Name As The Table Name, Says It Doesn't Exist

Thanks for response. I didn't realize it was the unique rule causing the problem, and you've helped me understand the unique rule better. But my goal is not user_id to be unique in the 'draws' table. It's a composite of user_id and round_id that needs to be unique in the draws table. I had thought that rule I had was working ok, don't know where I found it, but it must have been the schema definition that was kicking it back when I tested it:

$table->unique(['round_id', 'user_id']);

Can you show me what my validation rule needs to look like to make the composite of user_id-round_id be unique in the draws table? I've tried a bunch of other combinations but nothing has worked. Thanks

Jul
30
1 week ago
Activity icon

Started a new Conversation 1146 Error Shows Column Name As The Table Name, Says It Doesn't Exist

"Base table or view not found: 1146 Table '(my project name).round_id' doesn't exist (SQL: select count(*) as aggregate from round_id where user_id = 112" The error says my table name is 'round_id' but that's just one of the columns/form fields. The model is Draw and the table is draws. My controller is DrawController. I'm using resource controller so route does hit the right method (store), and I've tested the route with dumps. I've been getting this error since I applied validation to my form fields (first in the controller store() then moved to DrawRequest class rules()). If I comment out the validation, the store method will properly persist the input to the db. Even if I comment out the round_id line in the validation, error still says that's my table name. I can't find anything online with the validation as the apparent culprit. My validation looks like this:

    public function rules()
    {
        return [
                'round_id' => 'required',
                'user_id' => 'required|unique:round_id', 
                'hand_id' => 'required',
                'answer' => ['required','integer','max(999)'],
        ];
    }

Please help. Thanks

Jun
28
1 month ago
Activity icon

Replied to Query Builder Chain: ->upper() NOT Working In View

Wow, plenty of choices, thanks much. Stringable worked already. It seemed like such a straightforward query-chain non-problem. As much time as I've spent in the docs, stackoverflow, and everywhere else, haven't seen anything about Stringable before. Now I see it's only mentioned one time, only in the latest docs version, unless someone can point me to a prior occurrence that the search feature missed. Thanks again.

Activity icon

Started a new Conversation Query Builder Chain: ->upper() NOT Working In View

I'm trying to output a string in all caps: {{ $user->lastName->upper() }} and getting this error: "Call to a member function upper() on string." This seems to be right out of the docs: "$adjusted = Str::of('laravel')->upper();" What am I doing wrong? Thanks

Jun
13
1 month ago
Activity icon

Commented on Say Hello To Forge

Never mentioned what Forge is for, and didn't describe it in the About block.

May
18
2 months ago
Activity icon

Started a new Conversation Number The Rows In A Subquery Using Query Builder (or Eloquent)?

I'm trying to line up two sets of players (users), who have drawn different colors, opposite each other on the same table row of the view. The players who will occupy the same row have no common field value to join them except their row number from their subqueries. I need to number the rows in the subqueries so the first player to draw green appears in the same row as the first to draw yellow, and so on. Each subquery joins the players table and the draws table, and the outer query joins the two subs using the player's row number from their subquery. The subquery row numbers don't need to be displayed, they're just for lining up the rows.

Tables:

players: id, name (simplified user);
draws: id, player_id, color

Desired result (greatly simplified):

    Green     |Row|         Yellow
Name   Draw             Name     Draw
Joe   green     1       Ed      yellow
Mary  green     2       John    yellow
Sam   green     3       Clara   yellow

I was able to produce that view last year experimenting with php and raw sql, before I even heard of Laravel (or tried OOP). Recently I recreated the desired result in Laravel by concatenating pure sql into "DB::select($query)" (shown below), but it won't let me paginate that (unless someone can show me how). So how can I do this with Query Builder or Eloquent? I've made many attempts with Query Builder (one below). But the row number attempts in the subqueries either cause errors or just don't work.

Errors

Mysql won't accept "DB::raw('(@rownum:=@rownum+1) AS RowNumY'))" coming from Query Builder as a member of the field list even tho it accepted it from "DB::select($query)" in the concatenated version. Or it rejects "(SELECT @rownum:=0) AS Outerrow_num" in the FROM clause. Or when it was accepted in the FROM clause, it overwrote the base table (draws), so that the fields from that table (draws.color) didn't exist.

Concatenated raw sql version (this works):

$query = 'select colorY, playerY, ';                     // outer query fields
$query .= '@rownum:= @rownum + 1 AS row_numOuter, ';    // outer query row number
$query .= 'colorG, playerG ';                            // outer query fields
$query .= 'from (SELECT @rownum:=0) AS Outerrow_num, '; // set outer row number=0
$query .= '(select drawsG.color as colorG, ';            // start green subquery field list
$query .= 'playersG.name as playerG, ';
$query .= '(@rownumG:[email protected] + 1) AS RowNumG ';        // green subquery row number
$query .= 'from (select @rownumG:=0) AS rownumG, ';  // set green subquery row number=0
$query .= 'draws AS drawsG ';
$query .= 'inner join players as playersG ';            // join draws w/ players – green
$query .= 'on playersG.id = drawsG.player_id ';
$query .= 'where color = "green") ';
$query .= 'as drawsGreen ';                             // green subquery alias
$query .= 'right join ';             // join green and yellow subqueries (yellow on right-has more in my db)
$query .= '(select drawsY.color as colorY, ';           // start yellow subquery field list
$query .= 'playersY.name as playerY, ';
$query .= '(@rownumY:[email protected] + 1) AS RowNumY ';       // yellow subquery row number
$query .= 'from (select @rownumY:=0) AS rownumY, ';     // set yellow subquery row number=0
$query .= 'draws AS drawsY ';
$query .= 'inner join players as playersY ';            // join draws w/ players - yellow
$query .= 'on playersY.id = drawsY.player_id ';
$query .= 'where color = "yellow") ';
$query .= 'as drawsYellow ';                            // yellow subquery alias
$query .= 'on RowNumG = RowNumY';                       // ON clause for right join

$draws = DB::select($query);
return view('draws.index', compact(['draws']));

So here's my (latest?) attempt to do it via Query Builder:

$subQYellow = DB::table('draws AS drawsY')                 // yellow subquery, on draws table
    ->join('players AS playersY', 'playersY.id', '=', 'drawsY.player_id')    // join to players table on id
    ->select('color AS colorY', 'playersY.name AS playerY',         // yellow field list 
        DB::raw('(@rownum:[email protected]+1) AS RowNumY'))        // set yellow subquery row number=0
    ->from(DB::raw('(select @rownum:=0) AS rownumY'),          // from "list", yellow subquery row number
('draws AS drawsY'))                          // repeat draws table (??)
    ->where('color', 'yellow');              // color value filter

$subQGreen = DB::table('draws AS drawsG')                // green subquery, on draws table
    ->join('players AS playersG', 'playersG.id', '=', 'drawsG.player_id')    // join to players table on id
    ->select('color AS colorG', 'playersG.name AS playerG',         // green field list 
        DB::raw('(@rownum:[email protected]+1) AS RowNumG'))          // set yellow subquery row number=0
    ->from(DB::raw('(select @rownum:=0) AS rownumG'),             // from "list", green subquery row number 
('draws AS drawsG'))                              // repeat draws table (??)
    ->where('color', 'green');                   // color value filter

$draws = DB::table($subgreen, 'drawsGrn')                  // QB on subgreen w/alias
    ->select('colorY AS colorYlw', 'playerY AS playerYlw',        // outer query field list w/ aliases
'colorG AS colorGrn', 'playerG AS playerGrn')                  // more fields
    ->rightJoinSub($subyellow, 'drawsYlw', function ($join) {        // joinSub on yellow with closure
        $join->on('RowNumG', '=', 'RowNumY');                // outer query ON clause to join subs
    })              
    ->get();

Note: I had to repeat the draws table in FROM clause of each subquery because the row numbering code in the FROM clause seemed to overwrite it. If I put it in another ->from clause, the second FROM overwrites the first FROM. Catch 22. Note: I'm never sure when mysql needs aliases. Is there a rule? Any help? Thanks in advance.

Activity icon

Started a new Conversation Can't Seem To Ask A Question Here.

Won't post, times out when I use markdown.

Apr
05
4 months ago
Activity icon

Replied to Plural Controller/model Name Causes Not Found

w0lf, I know it's been a long time so you may not remember, but I'm a newbie and wondering what your composer error was all about, and how dump-autoload fixed it. I found this while trying to decide between plural and singular for controllers. Thanks

Feb
26
5 months ago
Activity icon

Commented on Help Me Understand CSRF

Barely helpful. Do you ever critically watch your own videos?