What is the benefit of Laravel's query builder?
I am learning to use Laravel 5, but I am at the query builder phase, and after looking at the first code snippets I think it is really useless when somebody has basic SQL knowledge.
$users = DB::table('users') ->select(DB::raw('count(*) as user_count, status')) ->where('status', '<>', 1) ->groupBy('status') ->get();
What is the purpose of learning query builder syntax if the programmer actually has at least basic knowledge about the SQL language? Moreover, moving advanced queries from a clean SQL language to query builder functions looks like a nightmare...
Other than it provides an interface for when you want to switch database engines (but to be honest, how many times have you seen a large application actually switch database engines?), I don't really see too many advantages. It is, of course, the more "Eloquent" and "Laravel" way of doing things - which by itself will be enough of a sell to the framework purists out there.
If anything, I think using query builder would make onboarding a new developer that much harder. SQL is a universal language that almost all developers know. If you have a new member on your team who doesn't know Laravel well, chances are it'll take him a day to get up to speed with query builder.
I have come to accept to using relationships in my Eloquent models for simple one table joins, or two table joins using a reference table. But anything requiring more than two joins, you should really be writing out your own SQL or using query builder. And out of the two choices, I personally prefer writing raw SQL.
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?