I have this query in mysql
SELECT id, name, (SELECT COUNT(id_team_local) FROM seasons WHERE id_team_local = teams.id) AS 'Partidos Jugados' FROM teams
and I would like to give Laravel some idea of how I could do it?
I have this query in mysql
SELECT id, name, (SELECT COUNT(id_team_local) FROM seasons WHERE id_team_local = teams.id) AS 'Partidos Jugados' FROM teams
and I would like to give Laravel some idea of how I could do it?
Taking into account that you do not specify if you are using Eloquent or if there are related models, I will give an example by directly accessing the database through the facade (DB) and the query builder:
$teams = DB::table('teams')
->select(DB::raw('id, name, (SELECT COUNT(id_team_local) FROM seasons WHERE id_team_local = teams.id) AS 'Partidos jugados'))
->get();
More information in the Laravel documentation: link