rajcsanyiz

rajcsanyiz

Web developer at Court of Zala County

Member Since 4 Years Ago

Zalaegerszeg

Experience Points
14,180
Total
Experience

820 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
178
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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
14,180 XP
Mar
14
7 months ago
Activity icon

Replied to Query Builder + Where + Inner Select

I found two solutions:

        $query = DB::table('tmteher_monthly_stats as tms')
            ->select('tms.user_id')
            ->addSelect('tms.dayoff')
            ->whereDate('tms.stat_date', '=', $period.'-01')
            ->where('tms.id', '=', function($query) {
                $query->from('tmteher_monthly_stats AS tms2')
                    ->selectRaw('max(tms2.id)')
                    ->whereRaw('tms2.user_id = tms.user_id')
                    ->whereRaw('tms2.stat_date = tms.stat_date');
            });
        $query = DB::table('tmteher_monthly_stats as tms')
            ->select('tms.user_id')
            ->addSelect('tms.dayoff')
            ->whereDate('tms.stat_date', '=', $period.'-01')
            ->where('tms.id', '=', function($query) {
                $query->select(DB::raw('max(tms2.id)'))
                    ->from('tmteher_monthly_stats AS tms2')
                    ->where('tms2.user_id', '=', DB::raw('tms.user_id'))
                    ->where('tms2.stat_date', '=', DB::raw('tms.stat_date'));
            });

Explanation:

The where expression doesn't use properly the apostrophes.

The inner select's where without DB::raw() recognize the field as string. So it's wrong: $query->where(`tms2`.`user_id` = 'tms.user_id')

This code helped me:

        DB::enableQueryLog();
        $query_success->get();
        $query_empty->get();
        dd(DB::getQueryLog());

Result:

array:2 [
  0 => array:3 [
    "query" => "select `tms`.`user_id`, `tms`.`dayoff` from `tmteher_monthly_stats` as `tms` where date(`tms`.`stat_date`) = ? and `tms`.`id` = (select max(tms2.id) from `tmteher_monthly_stats` as `tms2` where `tms2`.`user_id` = tms.user_id and `tms2`.`stat_date` = tms.stat_date)"
    "bindings" => array:1 [
      0 => "2019-02-01"
    ]
    "time" => 11.65
  ]
  1 => array:3 [
    "query" => "select `tms`.`user_id`, `tms`.`dayoff` from `tmteher_monthly_stats` as `tms` where date(`tms`.`stat_date`) = ? and `tms`.`id` = (select max(tms2.id) from `tmteher_monthly_stats` as `tms2` where `tms2`.`user_id` = ? and `tms2`.`stat_date` = ?)"
    "bindings" => array:3 [
      0 => "2019-02-01"
      1 => "tms.user_id"
      2 => "tms.stat_date"
    ]
    "time" => 0.71
  ]
]
Activity icon

Replied to Query Builder + Where + Inner Select

@BORISU - I need this query to make a summary report. User can close a specific months multiple times. The first select gather the statistic data but sometimes exists data multiple times per user. I think your suggestion is not answer clearly my question. I replace the where expression to whereDate. (It's cool)

Activity icon

Started a new conversation Query Builder + Where + Inner Select

I have a SQL query:

        SELECT tms.id,
                tms.user_id,
                tms.dayoff
               FROM tmteher_monthly_stats AS tms
              WHERE tms.stat_date = '2019-03-01'
                    AND tms.id = (
                    SELECT MAX(tms2.id)
                  FROM tmteher_monthly_stats AS tms2
                  WHERE tms2.user_id = tms.user_id
                    AND tms2.stat_date = tms.stat_date);

I would like to transform the previous SQL with the eloquent query builder. But this code returns an empty array (without error):

        $period = '2019-03';
        $query = DB::table('tmteher_monthly_stats as tms')
            ->select('tms.user_id')
            ->addSelect('tms.dayoff')       
            ->where('tms.stat_date', '=', $period.'-01')
            ->where('tms.id', '=', function($query) {
                $query->select(DB::raw('max(tms2.id)'))
                    ->from('tmteher_monthly_stats AS tms2')
                    ->where('tms2.user_id', '=', 'tms.user_id')
                    ->where('tms2.stat_date', '=', 'tms.stat_date');
            });

The outer (first) select works correct, but the inner select doesn't.

Oct
15
3 years ago
Activity icon

Replied to Ubuntu With Laravel 5.x Tutorials Please

I agree with xHer.

I use Windows 10 + VirtualBox with Debian servers (Laravel 4.2, 5.1, 5.2, 5.3) in my company. My IDE are PHPStorm, SublimeText + SQLYog (in windows) But I use Ubuntu, Debian, Linux Mint too learn Jeffrey training, because the MacOS and Linux are more similar than Win10.

The debugging, preprocessing (sass, coffescript) much more easier in a single (simple) environment. I think a little cumbersome to setup Win10, virtualbox and debuging, but Win10 is not proper to develop native. (I think)

So https://serversforhackers.com/ is very good, but I'll happy somebody answer the next questions in some videos (not Jeffrey, because he use Mac)

Laravel in Windows/Linux

  • PHPStorm in Linux

  • PHPStorm in Windows

  • Installing LAMP (Linux, Apache, MySQL, PHP)

  • Installing LNMP (Linux, NginX, MySQL, PHP)

  • Multiple PHP versions on Linux

  • Multiple PHP versions on Windows (WAMP, MAMP, ...)

  • Multiple Apache versions on Linux

  • Multiple Apache versions on Windows

  • Multiple NginX versions on Linux

  • Multiple NginX versions on Windows

  • Rights and permissions on Linux

Create developing environments on different OS

  • Create developer environment on Debian Desktop

  • Create developer environment on Ubuntu Desktop

  • Create developer environment on Linux Mint

  • Create developer environment on Windows 10

  • Advantages and disadvantages on different Linux (Debian, Ubuntu, Linux Mint, ...)

Sorry my poor English...