[{"content":"In this first chapter, we answer two questions: what is Git, and why use it?\nWhat you\u0026#39;ll learn\nWhat Git is, and the problem it solves Why every developer uses it, alone or in a team The difference between Git and GitHub The videos of this course are in French. Turn on YouTube\u0026rsquo;s auto-translated subtitles if needed: every chapter below is fully written in English.\nWhat is Git? The best-known definition: Git is a version control system. In practice, here\u0026rsquo;s what it does:\nIt tracks every file in your project: every change, addition or deletion is recorded. It keeps the history of all those changes. Broke part of the project? You can roll back to the last stable version. It knows who did what: every change is tied to the person who made it. Why use it? A simple example Picture a team working on the same project, each person on their own PC.\nWithout Git, everyone edits files on their side, then drops them into a shared folder. The result: people overwrite each other\u0026rsquo;s files, changes get lost, and nobody knows which version is the right one.\nWith Git, everyone pushes their changes to an online platform such as GitHub, GitLab or Bitbucket. The whole team can then pull those changes, build on top of them and push their own, without overwriting anything.\nIt\u0026rsquo;s a very simple example, but you\u0026rsquo;ll explore all of this in detail in the next chapters.\nGit or GitHub?\nThey\u0026rsquo;re often mixed up, but they\u0026rsquo;re two different things:\nGit is the tool, installed on your machine. It records your project\u0026rsquo;s history, even without an internet connection. GitHub is a website that hosts Git repositories online, and adds everything you need to work as a team: pull requests, code reviews, issues… GitLab and Bitbucket do the same. So you can use Git without GitHub. The other way round makes no sense.\nWhat\u0026rsquo;s Next Head to Git\u0026rsquo;s official website, git-scm.com, to download it. In the next chapter, we install and configure it together.\nThis is Chapter 1 of the Git in Practice course. Follow along to learn how to use Git every day and as a team.\n","permalink":"https://naimidevslayer.com/en/cours/outils/git/git-en-pratique/01-introduction/","summary":"\u003cp\u003eIn this first chapter, we answer two questions: \u003cstrong\u003ewhat is Git\u003c/strong\u003e, and \u003cstrong\u003ewhy use it\u003c/strong\u003e?\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/mpeFQm-AKIY?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eWhat Git is, and the problem it solves\u003c/li\u003e\n\u003cli\u003eWhy every developer uses it, alone or in a team\u003c/li\u003e\n\u003cli\u003eThe difference between Git and GitHub\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003cblockquote\u003e\n\u003cp\u003eThe videos of this course are in French. Turn on YouTube\u0026rsquo;s auto-translated subtitles if needed: every chapter below is fully written in English.\u003c/p\u003e","title":"Git in Practice #1: What Is Git, and Why Use It?"},{"content":"Welcome to this new series where we dive into the world of SQL, the essential language for managing and querying databases. Whether you\u0026rsquo;re a beginner, want to refresh your knowledge, or just want to understand why SQL is everywhere in tech, you\u0026rsquo;re in the right place.\nWhat you\u0026#39;ll learn\nThe course outline, from databases to joins What you\u0026rsquo;ll be able to do by the end: create, link and query tables How to work through the chapters so it really sticks The videos of this course are in French. Turn on YouTube\u0026rsquo;s auto-translated subtitles if needed: every chapter below is fully written in English.\nThe program Here\u0026rsquo;s what we\u0026rsquo;ll cover, chapter by chapter:\nWhat is SQL? Why this language matters so much in modern database management, then installing MySQL, one of the most popular database management systems. Managing databases: creating, deleting, renaming and switching between them. Managing tables: creating, modifying and linking them, then inserting, updating and deleting data. Querying data with SELECT: filtering, sorting, grouping and calculating. Advanced SQL: subqueries, for more powerful queries. Advanced SQL: joins, to combine data from several tables. Hands-on exercises, in two parts, to put everything into practice. The goal: by the end of the course, you\u0026rsquo;ll walk away with real hands-on SQL experience.\nHow to follow this course\nType every query yourself, even the ones that look obvious, instead of copy-pasting them. Make a mistake, read MySQL\u0026rsquo;s message, fix it: that\u0026rsquo;s how the syntax sinks in. And at the end of each chapter, do the exercise before opening the solution.\nWhat\u0026rsquo;s Next In the next chapter, we answer the question: what is SQL, and why does it matter so much? Then we install MySQL.\nThis is Chapter 1 of the SQL from Zero to Pro course. Follow along to learn SQL with MySQL, from the basics to joins.\n","permalink":"https://naimidevslayer.com/en/cours/bases-de-donnees/mysql/sql-de-zero-a-pro/01-introduction/","summary":"\u003cp\u003eWelcome to this new series where we dive into the world of \u003cstrong\u003eSQL\u003c/strong\u003e, the essential language for managing and querying databases. Whether you\u0026rsquo;re a beginner, want to refresh your knowledge, or just want to understand why SQL is everywhere in tech, you\u0026rsquo;re in the right place.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/nDU-eGIpn_c?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e","title":"SQL from Zero to Pro #1: Course Introduction"},{"content":"Welcome to a brand new tutorial series where we won\u0026rsquo;t just cover Symfony theory — we\u0026rsquo;re going to build a real project together: a mini digital library application.\nThis is Chapter 1 of the Mini Library course. If you\u0026rsquo;re new here, this series will take you from an empty folder to a fully working app with a public catalog, PDF reading, and a complete EasyAdmin dashboard.\nWhat you\u0026#39;ll learn\nWhat we\u0026rsquo;ll build in this course, and why it\u0026rsquo;s a real project The tools to install: WAMP, Composer, Symfony CLI and VS Code How to check that your machine is ready with symfony check:requirements What We\u0026rsquo;re Building Throughout this series, we\u0026rsquo;ll create:\nA clean, modern interface where users can browse books by their covers A built-in PDF reader so users can read books directly online A powerful admin dashboard built with EasyAdmin, letting us manage the entire catalog — books, authors, categories, users — in just a few clicks EasyAdmin is only one part of this course. By the end, you\u0026rsquo;ll have touched authentication, file handling, PDF streaming, and more — all inside a real, working Symfony 8 project.\nSetting Up the Development Environment Before writing a single line of Symfony code, we need a proper local environment. Here\u0026rsquo;s exactly what\u0026rsquo;s needed and why.\n1. WAMP (Apache, PHP, MySQL) WAMP bundles the three things we need to run PHP locally:\nApache as the web server PHP as the language runtime MySQL as the database Download it directly from the official WAMP website.\nMissing a recent PHP version? If your WAMP install doesn\u0026rsquo;t include PHP 8.4 or 8.5, you can add the required extensions via wampserver.aviatechno.net. For this course, we\u0026rsquo;re running PHP 8.5.3.\n2. Composer Composer is the dependency manager we\u0026rsquo;ll use to install Symfony and every package throughout this course.\n3. Symfony CLI Think of the Symfony CLI as your personal assistant for this project. It lets you:\nCreate new Symfony projects Check whether your system is properly configured Run the local development server with a single command Install it from the official Symfony documentation — instructions are available for Windows, Linux, Mac, and Docker.\n4. Code Editor: VS Code You can use any editor you like, but this course uses VS Code with a few extensions that make Symfony development noticeably smoother:\nPHP Debug PHP Intelephense Twig extension (for proper Twig syntax support) SonarLint / SonarQube (to help keep code quality in check) Verifying Your Setup Before installing Symfony itself, run this command:\nsymfony check:requirements This checks that everything on your machine is properly configured to run a Symfony project — PHP version, required extensions, and more.\nHere\u0026rsquo;s what to expect:\nphp -v # PHP 8.5.0 symfony check:requirements # ✔ Your system is ready to run Symfony projects If you see a confirmation like this, your environment is ready.\nCommon mistake\nsymfony check:requirements shows errors? Most of the time, a PHP extension is missing, such as intl or pdo_mysql. To see which ones are enabled:\nphp -m With WAMP, enable the missing extension by clicking the WAMP icon → PHP → PHP extensions, or remove the ; in front of the extension=intl line in your php.ini, then restart the services.\nAlso check that your terminal uses the right PHP: php -v must show the same version as the one selected in WAMP. Otherwise, your PATH points to another PHP installation.\nGoing further\nWAMP isn\u0026rsquo;t the only option. On Windows, Laragon is a lightweight and popular alternative. On macOS and Linux, you can install PHP with your package manager (brew, apt) and let the Symfony CLI serve the project. And for an identical setup on every team member\u0026rsquo;s machine, Docker is the most robust solution: we\u0026rsquo;ll get there in the deployment part.\nExercise · Get your machine ready\nCheck your setup with three commands: the PHP version, the Composer version, then the Symfony requirements.\nShow the solution php -v composer --version symfony check:requirements All three must answer without errors, and the last one must end with \u0026ldquo;Your system is ready to run Symfony projects\u0026rdquo;.\nWhat\u0026rsquo;s Next That\u0026rsquo;s it for this introduction — our development environment is fully set up. In the next chapter, we\u0026rsquo;ll move on to the real work: installing our Symfony 8 project and integrating our first template.\nThis is Chapter 1 of the Mini Library course. Follow along to build a complete Symfony 8 + EasyAdmin digital library application from scratch.\n","permalink":"https://naimidevslayer.com/en/cours/developpement-web/symfony-8/mini-bibliotheque/01-introduction/","summary":"\u003cp\u003eWelcome to a brand new tutorial series where we won\u0026rsquo;t just cover Symfony theory — we\u0026rsquo;re going to \u003cstrong\u003ebuild a real project together\u003c/strong\u003e: a mini digital library application.\u003c/p\u003e\n\u003cp\u003eThis is \u003cstrong\u003eChapter 1\u003c/strong\u003e of the Mini Library course. If you\u0026rsquo;re new here, this series will take you from an empty folder to a fully working app with a public catalog, PDF reading, and a complete EasyAdmin dashboard.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/0oUd5R5RYcA?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e","title":"Mini Library Course #1: Introduction \u0026 Setting Up Your Symfony 8 Environment"},{"content":"To use Git, you just need to install it on your machine and tell it who you are.\nWhat you\u0026#39;ll learn\nInstall Git on your machine Check that the installation works Set your name and email, once and for all Installing Git Go to the official website, git-scm.com, under Downloads. Pick your system, then the 64-bit version (unless your machine is 32-bit). Take the regular installer, not the \u0026ldquo;portable\u0026rdquo; version. Run the installer. A standard installation is enough: keep the default options. Checking the installation git --version # git version 2.30.1.windows.1 If the command prints a version, Git is installed.\nSetting your identity As we saw in the previous chapter, Git records who makes each change. So you need to give it your name and email:\ngit config --global user.name \u0026#34;Your Name\u0026#34; git config --global user.email \u0026#34;your.email@example.com\u0026#34; --global applies the setting to all your projects on this machine. This name and email will appear in every commit and push you make. Use the same email as your GitHub account: your commits will then be linked to your profile.\nTo check your configuration:\ngit config --global --list Two settings that make life easier\nTo have Git open VS Code when it needs a message (a commit without -m, a merge…), instead of the Vim editor that traps so many people:\ngit config --global core.editor \u0026#34;code --wait\u0026#34; And to see your whole configuration, with where each value is set:\ngit config --list --show-origin Common mistake\nYour commits don\u0026rsquo;t show up on your GitHub profile? The email set in Git doesn\u0026rsquo;t match any email on your account. Check it with git config --global user.email, and add it if needed in GitHub\u0026rsquo;s settings (Settings → Emails).\nExercise · Check your identity\nShow the name and email Git will use for your next commits.\nShow the solution git config --global user.name git config --global user.email With no value after the setting\u0026rsquo;s name, git config shows the current value instead of changing it.\nWhat\u0026rsquo;s Next Git is ready! In the next chapter, we use it on a real project: clone, create a branch, commit and push.\nThis is Chapter 2 of the Git in Practice course. Follow along to learn how to use Git every day and as a team.\n","permalink":"https://naimidevslayer.com/en/cours/outils/git/git-en-pratique/02-installation-configuration/","summary":"\u003cp\u003eTo use Git, you just need to install it on your machine and tell it who you are.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/3AJNLIrHupQ?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eInstall Git on your machine\u003c/li\u003e\n\u003cli\u003eCheck that the installation works\u003c/li\u003e\n\u003cli\u003eSet your name and email, once and for all\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"installing-git\"\u003eInstalling Git\u003c/h2\u003e\n\u003col\u003e\n\u003cli\u003eGo to the official website, \u003cstrong\u003egit-scm.com\u003c/strong\u003e, under \u003cstrong\u003eDownloads\u003c/strong\u003e.\u003c/li\u003e\n\u003cli\u003ePick your system, then the \u003cstrong\u003e64-bit\u003c/strong\u003e version (unless your machine is 32-bit). Take the regular installer, not the \u0026ldquo;portable\u0026rdquo; version.\u003c/li\u003e\n\u003cli\u003eRun the installer. A \u003cstrong\u003estandard installation\u003c/strong\u003e is enough: keep the default options.\u003c/li\u003e\n\u003c/ol\u003e\n\u003ch2 id=\"checking-the-installation\"\u003eChecking the installation\u003c/h2\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" class=\"chroma\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003egit --version\n\u003c/span\u003e\u003c/span\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003e\u003cspan class=\"c1\"\u003e# git version 2.30.1.windows.1\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eIf the command prints a version, Git is installed.\u003c/p\u003e","title":"Git in Practice #2: Installing and Configuring Git"},{"content":"In this chapter, we answer the question \u0026ldquo;what is SQL?\u0026rdquo;, see why it\u0026rsquo;s used everywhere, then install MySQL.\nWhat you\u0026#39;ll learn\nWhat SQL is, and what a DBMS like MySQL is Why SQL is still a must-have for a developer Install MySQL with WAMP and open phpMyAdmin What is SQL? SQL stands for Structured Query Language. It\u0026rsquo;s a language designed to query, manipulate and manage data in relational databases.\nA relational database stores information in tables. For example, a database can contain a person table and a city table:\neach table has columns, and each column stores one specific kind of information; tables can be linked together: a person lives in a city. We\u0026rsquo;ll cover these relationships in detail in the coming chapters. Why use SQL? Everything that deals with data, whether it\u0026rsquo;s a website, an app or a company, relies on databases. SQL is the key to accessing them: it lets you retrieve specific information, sort it, filter it and update it.\nIt\u0026rsquo;s also usable from most programming languages. In PHP, for example, the MySQLi and PDO extensions run SQL queries directly: everything you learn here works as-is in your projects.\nAnother concrete example: turning an Excel file into a table. A file with name, birthday and city columns becomes a table with the same columns, plus an id for each row.\nInstalling MySQL MySQL is a relational database management system (RDBMS) widely used to store data for web applications. It\u0026rsquo;s a personal choice for this course: PostgreSQL or Oracle work too.\nYou have several ways to install it:\nSystem Tool What it installs Windows WAMP Apache, MySQL (and MariaDB), PHP and phpMyAdmin Linux LAMP Apache, MySQL and PHP Any Official MySQL website MySQL alone, plus MySQL Workbench if you want a GUI For a web developer who mainly works with PHP, WAMP on Windows (or LAMP on Linux) is the most convenient: everything gets installed at once.\nInstalling WAMP Search for WampServer on Google and open the official website. Download the latest 64-bit version. It installs Apache 2.4, several PHP versions (up to 8.4), MySQL 9.1, MariaDB and phpMyAdmin. Run the .exe file and follow the installer. Start WAMP: its icon appears in the taskbar. When it turns green, all services are running. Opening phpMyAdmin Click the WAMP icon, then phpMyAdmin, or go straight to http://localhost/phpmyadmin.\nChoose the MySQL server. User: root, with no password by default. You land on an interface that lists all your databases. Click a database to see its tables.\nphpMyAdmin is very handy, but in this course we\u0026rsquo;ll mainly learn to write real SQL queries. GUIs will come later to save you time.\nMySQL or MariaDB?\nWAMP often installs MySQL and MariaDB side by side. MariaDB is a fork of MySQL, created by its founders: for this whole course, both behave the same way, apart from a few details I\u0026rsquo;ll point out along the way.\nTo find out which one you\u0026rsquo;re connected to, run this query in phpMyAdmin\u0026rsquo;s SQL tab:\nSELECT VERSION(); -- 8.0.31 → MySQL -- 10.11.6-MariaDB → MariaDB And outside WAMP: MySQL Workbench and DBeaver are very good graphical clients, and Docker lets you start a MySQL server with one command, without installing anything else.\nWhat\u0026rsquo;s Next In the next chapter, we create and delete our first databases, from the command line and with phpMyAdmin.\nThis is Chapter 2 of the SQL from Zero to Pro course. Follow along to learn SQL with MySQL, from the basics to joins.\n","permalink":"https://naimidevslayer.com/en/cours/bases-de-donnees/mysql/sql-de-zero-a-pro/02-sql-installation-mysql/","summary":"\u003cp\u003eIn this chapter, we answer the question \u003cstrong\u003e\u0026ldquo;what is SQL?\u0026rdquo;\u003c/strong\u003e, see why it\u0026rsquo;s used everywhere, then install \u003cstrong\u003eMySQL\u003c/strong\u003e.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/-rrXv2B8Ti0?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eWhat SQL is, and what a DBMS like MySQL is\u003c/li\u003e\n\u003cli\u003eWhy SQL is still a must-have for a developer\u003c/li\u003e\n\u003cli\u003eInstall MySQL with WAMP and open phpMyAdmin\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"what-is-sql\"\u003eWhat is SQL?\u003c/h2\u003e\n\u003cp\u003e\u003cstrong\u003eSQL\u003c/strong\u003e stands for \u003cem\u003eStructured Query Language\u003c/em\u003e. It\u0026rsquo;s a language designed to \u003cstrong\u003equery, manipulate and manage data\u003c/strong\u003e in \u003cstrong\u003erelational databases\u003c/strong\u003e.\u003c/p\u003e","title":"SQL from Zero to Pro #2: What Is SQL? Installing MySQL"},{"content":"In Chapter 1, we set up our development environment. Now it\u0026rsquo;s time for the real work. In this chapter we do two things:\nInstall our Symfony 8 project, following the official documentation step by step Integrate an HTML/CSS template, so our app looks good from day one What you\u0026#39;ll learn\nCreate a Symfony 8 project with the Symfony CLI (and what --webapp changes) Start the local server and generate your first controller Understand a request\u0026rsquo;s journey: route, controller, template Integrate an HTML/CSS template with Twig and AssetMapper Installing a Symfony 8 Project We already ran symfony check:requirements in the previous chapter, so our machine is ready. The official documentation gives us two ways to create a project.\nOption 1: Symfony CLI (recommended) symfony new minibib --version=8.* --webapp The --webapp option installs a traditional web application with every component you need: Twig, Doctrine, forms, security, and more.\nWithout --webapp, Symfony installs only the minimal skeleton, which is what you\u0026rsquo;d use for a console application, an API, or a microservice.\nOption 2: Composer composer create-project symfony/skeleton minibib cd minibib composer require webapp This gives the same result in two steps: first a minimal project, then the web application components.\nWe\u0026rsquo;ll use the Symfony CLI, since it\u0026rsquo;s the simplest method. Our project is called minibib. Once it\u0026rsquo;s created, step into the folder and open it in VS Code:\ncd minibib code . You now have a complete Symfony project that runs out of the box.\nStarting the Local Server symfony server:start The app is now available at http://127.0.0.1:8000. The project is still empty, but you\u0026rsquo;ll already see the Symfony welcome page.\nCreating Our First Controller Our controller will display our template on a specific route.\nTwo ways to run console commands Symfony ships with a console that can generate controllers, entities, event subscribers, and much more. You can call it in two equivalent ways:\nphp bin/console \u0026lt;command\u0026gt; # or symfony console \u0026lt;command\u0026gt; Both run exactly the same commands.\nGenerating the controller symfony console make:controller HomeController We don\u0026rsquo;t need PHPUnit tests for now, so we answer no when asked. The command creates two files:\nFile Role src/Controller/HomeController.php The PHP logic templates/home/index.html.twig The HTML interface, written in Twig Here\u0026rsquo;s the generated controller:\n\u0026lt;?php namespace App\\Controller; use Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController; use Symfony\\Component\\HttpFoundation\\Response; use Symfony\\Component\\Routing\\Attribute\\Route; final class HomeController extends AbstractController { #[Route(\u0026#39;/home\u0026#39;, name: \u0026#39;app_home\u0026#39;)] public function index(): Response { return $this-\u0026gt;render(\u0026#39;home/index.html.twig\u0026#39;, [ \u0026#39;controller_name\u0026#39; =\u0026gt; \u0026#39;HomeController\u0026#39;, ]); } } Symfony created a /home route for us. The controller method is where the application logic lives, such as fetching data from the database or running calculations. It then returns the template with render().\nVisit http://127.0.0.1:8000/home: the HomeController page shows up.\nBrowser GET /home Route app_home Controller HomeController Twig render() Response HTML the HTML page goes back to the browser A request\u0026rsquo;s journey: the route picks the controller, which renders a Twig template, sent back to the browser as an HTML page. Integrating the Template For this project I\u0026rsquo;m using a free template made of one HTML file and one CSS file. Here\u0026rsquo;s how to plug it into Symfony.\n1. Replace the Twig content Open templates/home/index.html.twig, remove the generated content, and paste the template\u0026rsquo;s HTML inside the body block:\n{% extends \u0026#39;base.html.twig\u0026#39; %} {% block body %} {# the template\u0026#39;s HTML goes here #} {% endblock %} 2. Add the CSS with AssetMapper Symfony 8 uses AssetMapper. Copy the template\u0026rsquo;s CSS into assets/styles/app.css. That file is already loaded automatically through the importmap configuration, so there\u0026rsquo;s nothing else to wire up.\n3. Put global links in base.html.twig External stylesheets used everywhere in the app, like Bootstrap, belong in templates/base.html.twig:\n\u0026lt;head\u0026gt; \u0026lt;meta charset=\u0026#34;UTF-8\u0026#34;\u0026gt; \u0026lt;title\u0026gt;{% block title %}Welcome!{% endblock %}\u0026lt;/title\u0026gt; \u0026lt;link rel=\u0026#34;stylesheet\u0026#34; href=\u0026#34;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\u0026#34;\u0026gt; \u0026lt;link href=\u0026#34;https://fonts.googleapis.com/css?family=Droid+Sans:400,700\u0026#34; rel=\u0026#34;stylesheet\u0026#34;\u0026gt; \u0026lt;link rel=\u0026#34;stylesheet\u0026#34; href=\u0026#34;https://cdnjs.cloudflare.com/ajax/libs/baguettebox.js/1.8.1/baguetteBox.min.css\u0026#34;\u0026gt; {% block stylesheets %}{% endblock %} {% block javascripts %} {% block importmap %}{{ importmap(\u0026#39;app\u0026#39;) }}{% endblock %} {% endblock %} \u0026lt;/head\u0026gt; The template\u0026rsquo;s JavaScript files go in base.html.twig too.\nGlobal vs. page-specific: styles and scripts used across the whole app go in base.html.twig. If a style or script is only needed on one page, add it in that page\u0026rsquo;s template using the stylesheets or javascripts Twig blocks.\n4. Move the images to public/ Copy the template\u0026rsquo;s images folder into public/. Files in public/ are served directly to the browser, which is exactly what images need.\nTip\nIn your templates, reference those images with the Twig asset() function rather than a hard-coded path:\n\u0026lt;img src=\u0026#34;{{ asset(\u0026#39;images/cover.jpg\u0026#39;) }}\u0026#34; alt=\u0026#34;Cover\u0026#34;\u0026gt; asset() builds the right path whatever the site\u0026rsquo;s URL, for example if the app is one day installed in a subfolder. A relative path like images/cover.jpg breaks as soon as the page lives at another address, like /books/42.\nRefresh the page: the template is integrated and looks exactly like the original.\nGoing further\nTo see every route in your application, with its URL and controller:\nsymfony console debug:router And to make the home page answer on / rather than /home, just change the attribute: #[Route('/', name: 'app_home')].\nRecap Create a project: symfony new \u0026lt;name\u0026gt; --webapp takes a few seconds Start the server: symfony server:start Create a controller: symfony console make:controller CSS: goes in assets/ (AssetMapper) or in public/ Global styles and scripts go in base.html.twig, while page-specific code goes in the matching template Exercise · A second page\nCreate an \u0026ldquo;About\u0026rdquo; page at /about, with its own controller and template, extending base.html.twig.\nShow the solution symfony console make:controller AboutController Then adjust the generated route:\n#[Route(\u0026#39;/about\u0026#39;, name: \u0026#39;app_about\u0026#39;)] public function index(): Response { return $this-\u0026gt;render(\u0026#39;about/index.html.twig\u0026#39;); } And in templates/about/index.html.twig:\n{% extends \u0026#39;base.html.twig\u0026#39; %} {% block title %}About{% endblock %} {% block body %} \u0026lt;h1\u0026gt;About the Mini Library\u0026lt;/h1\u0026gt; {% endblock %} What\u0026rsquo;s Next The template currently opens an image when you click an item. In our library, clicking a book cover will instead lead to a page that shows the book\u0026rsquo;s PDF content. So we\u0026rsquo;ve already removed the parts of the template we don\u0026rsquo;t need, and later we\u0026rsquo;ll point the links to our own pages.\nIn the next chapter, we\u0026rsquo;ll set up the database, entities, and migrations.\nThis is Chapter 2 of the Mini Library course. Follow along to build a complete Symfony 8 + EasyAdmin digital library application from scratch.\n","permalink":"https://naimidevslayer.com/en/cours/developpement-web/symfony-8/mini-bibliotheque/02-installation-template-controller/","summary":"\u003cp\u003eIn \u003ca href=\"/en/cours/developpement-web/symfony-8/mini-bibliotheque/01-introduction/\"\u003eChapter 1\u003c/a\u003e, we set up our development environment. Now it\u0026rsquo;s time for the real work. In this chapter we do two things:\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003e\u003cstrong\u003eInstall our Symfony 8 project\u003c/strong\u003e, following the official documentation step by step\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eIntegrate an HTML/CSS template\u003c/strong\u003e, so our app looks good from day one\u003c/li\u003e\n\u003c/ol\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/zsffxoRsG5c?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e","title":"Mini Library Course #2: Installing Symfony 8, Your First Controller \u0026 Template Integration"},{"content":"Time to practice! We grab an existing project, create a branch, make some changes, then send them to the server.\nWhat you\u0026#39;ll learn\nGit\u0026rsquo;s basic cycle on a real project Clone, create a branch, edit, commit, push What git add, git commit and git push really do 1. Clone the project On the repository page (GitHub, Bitbucket…), copy the project URL, then:\ngit clone https://github.com/\u0026lt;user\u0026gt;/\u0026lt;project\u0026gt;.git cd \u0026lt;project\u0026gt; The project is now on your machine. Open it in your editor.\n2. Create a branch First, check which branch you\u0026rsquo;re on:\ngit branch # * master We don\u0026rsquo;t work directly on master. We create a branch for our changes:\ngit checkout -b develop # Switched to a new branch \u0026#39;develop\u0026#39; -b creates the branch and switches to it. With recent Git versions, git switch -c develop does the same.\n3. Make some changes For the example, we make three kinds of changes:\nmodify a file (delete a line); delete a file; add a new file, label.txt. 4. See what changed: git status git status Git lists the files:\nmodified: changed; deleted: removed; untracked files: new files, not yet tracked by Git. 5. Stage the files: git add Choose what goes into the next commit. Either file by file:\ngit add label.txt Or all at once:\ngit add . Run git status again: staged files turn green, the others stay red.\n6. Save: git commit git commit -m \u0026#34;Test changes\u0026#34; # 3 files changed, 2 insertions(+), 1 deletion(-) The message should describe what you did in this commit. Git then sums up the changes: files touched, lines added and removed.\n7. Send to the server: git push git push # fatal: The current branch develop has no upstream branch. The develop branch only exists on your machine: the server doesn\u0026rsquo;t know it yet. Git tells you the command to run:\ngit push --set-upstream origin develop --set-upstream (or -u) links your local branch to the server branch. Next time, a plain git push is enough.\nWorking directory Staging area Local repository Remote (GitHub) git add git commit git push git pull A change\u0026rsquo;s journey: git add stages it, git commit saves it in your local repository, git push sends it to the server. git pull goes the other way. Check on the platform Refresh the repository page: the develop branch shows up next to master. You\u0026rsquo;ll see your commit with its message, and clicking it shows every change in detail: the deleted line, the added file, the removed file.\n“rejected… fetch first” when pushing\nSomeone pushed to the same branch since your last update: the server has commits you don\u0026rsquo;t. Git refuses to overwrite their work. Get their changes first, then push:\ngit pull git push And resist the urge to git push --force on a shared branch: that\u0026rsquo;s exactly what wipes out other people\u0026rsquo;s work.\nRecap Command Role git clone \u0026lt;url\u0026gt; Get a project git branch List branches and the current one git checkout -b \u0026lt;name\u0026gt; Create a branch and switch to it git status See changed files git add \u0026lt;file\u0026gt; / git add . Stage files for the commit git commit -m \u0026quot;message\u0026quot; Save the changes git push -u origin \u0026lt;branch\u0026gt; Send a new branch to the server Exercise · A full cycle\nOn your project, create a docs/readme branch, add a line to README.md, then commit and push that branch to the server.\nShow the solution git checkout -b docs/readme # or: git switch -c docs/readme # … edit README.md … git status git add README.md git commit -m \u0026#34;Expand the README\u0026#34; git push --set-upstream origin docs/readme --set-upstream (or -u) is only needed on the branch\u0026rsquo;s first push. After that, a plain git push is enough.\nWhat\u0026rsquo;s Next Here, the project already existed on the server. In the next chapter, we start from scratch: git init, then push the project to GitHub.\nThis is Chapter 3 of the Git in Practice course. Follow along to learn how to use Git every day and as a team.\n","permalink":"https://naimidevslayer.com/en/cours/outils/git/git-en-pratique/03-cloner-branche-commit-push/","summary":"\u003cp\u003eTime to practice! We grab an existing project, create a branch, make some changes, then send them to the server.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/bm_u0MtggvI?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eGit\u0026rsquo;s basic cycle on a real project\u003c/li\u003e\n\u003cli\u003eClone, create a branch, edit, commit, push\u003c/li\u003e\n\u003cli\u003eWhat \u003ccode\u003egit add\u003c/code\u003e, \u003ccode\u003egit commit\u003c/code\u003e and \u003ccode\u003egit push\u003c/code\u003e really do\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"1-clone-the-project\"\u003e1. Clone the project\u003c/h2\u003e\n\u003cp\u003eOn the repository page (GitHub, Bitbucket…), copy the project URL, then:\u003c/p\u003e","title":"Git in Practice #3: Clone, Branch, Commit and Push"},{"content":"In this chapter, we learn to manage databases: create them, delete them, rename them and switch from one to another.\nWhat you\u0026#39;ll learn\nConnect to MySQL from the command line Create, delete, list and select a database Rename a database (there\u0026rsquo;s no command for that!) Pick the right encoding from the start The two basic commands -- Create a database CREATE DATABASE database_name; -- Delete a database DROP DATABASE database_name; You can do the same with a GUI (phpMyAdmin, Workbench…). Here, though, we use the command line: the terminal on Linux, the Command Prompt (CMD) on Windows.\nConnecting to MySQL from the command line Before running any command, you need to connect to the MySQL server:\nmysql -u root -p -h 127.0.0.1 Option Role -u The user, here root -p Prompts for the password (WAMP has none by default: just press Enter) -h The server host, here 127.0.0.1 since we\u0026rsquo;re working locally On Windows, if the mysql command isn\u0026rsquo;t recognized, run it from the MySQL bin folder inside WAMP, or add that folder to your PATH.\nCreating and deleting a database CREATE DATABASE test_safe; -- Query OK, 1 row affected DROP DATABASE test_safe; Don\u0026rsquo;t forget the semicolon at the end of every command.\nCreate the database again, then refresh phpMyAdmin: test_safe shows up, empty. Delete it with DROP DATABASE, refresh, and it\u0026rsquo;s gone.\nWith phpMyAdmin Create: click New database, give it a name and confirm. Keep the default collation for now. Delete: open the database, go to the Operations tab, then Drop the database (DROP). Renaming a database There is no RENAME DATABASE command in MySQL. We go through a few steps instead:\n# 1. Export the old database into a SQL file mysqldump -u root -p old_database \u0026gt; backup.sql # 2. Create the new database mysql -u root -p -e \u0026#34;CREATE DATABASE new_database\u0026#34; # 3. Import the content into the new database mysql -u root -p new_database \u0026lt; backup.sql # 4. Once everything is checked, delete the old database mysql -u root -p -e \u0026#34;DROP DATABASE old_database\u0026#34; \u0026gt; sends the output of mysqldump into the backup.sql file. \u0026lt; does the opposite: it feeds the file\u0026rsquo;s content to MySQL. Delete the old database last, after checking that the import worked. That way you lose nothing if a step fails.\nWith phpMyAdmin, it\u0026rsquo;s faster: open the database, go to the Operations tab, then Rename database to.\nMy advice: learn the commands first, then use GUIs to save time. That way you always know what\u0026rsquo;s happening behind the scenes.\nListing databases and picking one -- Show every database on the server SHOW DATABASES; -- Work on a specific database USE test_safe_1; -- Database changed On a server with several databases, USE tells MySQL which one you want to work on: every following command applies to it.\nThe right encoding from the start\nSet the encoding when you create the database: utf8mb4 handles every character, accents and emojis alike.\nCREATE DATABASE blog CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; On MySQL 8, utf8mb4 is already the default. But on older versions the default was latin1, and MySQL\u0026rsquo;s old utf8 can\u0026rsquo;t store emojis. Spelling it out costs nothing.\nWatch out\nDROP DATABASE is permanent: no trash, no undo. Before deleting a database that holds data, back it up with mysqldump, just like for renaming.\nFor scripts that don\u0026rsquo;t fail when the database already exists (or doesn\u0026rsquo;t), add IF EXISTS / IF NOT EXISTS:\nCREATE DATABASE IF NOT EXISTS blog; DROP DATABASE IF EXISTS blog; Recap Command Role CREATE DATABASE name; Create a database DROP DATABASE name; Delete a database SHOW DATABASES; List databases USE name; Pick the database to work on mysqldump + import Rename (or back up) a database Exercise · A database for a blog\nFrom the command line: create a blog database in utf8mb4, check that it shows up in the list, select it, then delete it.\nShow the solution CREATE DATABASE blog CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; SHOW DATABASES; USE blog; DROP DATABASE blog; What\u0026rsquo;s Next In the next chapter, we fill our database: tables, relationships and data manipulation.\nThis is Chapter 3 of the SQL from Zero to Pro course. Follow along to learn SQL with MySQL, from the basics to joins.\n","permalink":"https://naimidevslayer.com/en/cours/bases-de-donnees/mysql/sql-de-zero-a-pro/03-gestion-bases-de-donnees/","summary":"\u003cp\u003eIn this chapter, we learn to \u003cstrong\u003emanage databases\u003c/strong\u003e: create them, delete them, rename them and switch from one to another.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/u9YaDkzRCFA?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eConnect to MySQL from the command line\u003c/li\u003e\n\u003cli\u003eCreate, delete, list and select a database\u003c/li\u003e\n\u003cli\u003eRename a database (there\u0026rsquo;s no command for that!)\u003c/li\u003e\n\u003cli\u003ePick the right encoding from the start\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"the-two-basic-commands\"\u003eThe two basic commands\u003c/h2\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" class=\"chroma\"\u003e\u003ccode class=\"language-sql\" data-lang=\"sql\"\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003e\u003cspan class=\"c1\"\u003e-- Create a database\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003e\u003cspan class=\"c1\"\u003e\u003c/span\u003e\u003cspan class=\"k\"\u003eCREATE\u003c/span\u003e\u003cspan class=\"w\"\u003e \u003c/span\u003e\u003cspan class=\"k\"\u003eDATABASE\u003c/span\u003e\u003cspan class=\"w\"\u003e \u003c/span\u003e\u003cspan class=\"n\"\u003edatabase_name\u003c/span\u003e\u003cspan class=\"p\"\u003e;\u003c/span\u003e\u003cspan class=\"w\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003e\u003cspan class=\"w\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003e\u003cspan class=\"w\"\u003e\u003c/span\u003e\u003cspan class=\"c1\"\u003e-- Delete a database\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003e\u003cspan class=\"c1\"\u003e\u003c/span\u003e\u003cspan class=\"k\"\u003eDROP\u003c/span\u003e\u003cspan class=\"w\"\u003e \u003c/span\u003e\u003cspan class=\"k\"\u003eDATABASE\u003c/span\u003e\u003cspan class=\"w\"\u003e \u003c/span\u003e\u003cspan class=\"n\"\u003edatabase_name\u003c/span\u003e\u003cspan class=\"p\"\u003e;\u003c/span\u003e\u003cspan class=\"w\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eYou can do the same with a GUI (phpMyAdmin, Workbench…). Here, though, we use the \u003cstrong\u003ecommand line\u003c/strong\u003e: the terminal on Linux, the Command Prompt (CMD) on Windows.\u003c/p\u003e","title":"SQL from Zero to Pro #3: Create, Delete and Rename a Database"},{"content":"Our app runs and has a template. Now it needs data. In this chapter we connect Symfony to a MySQL database, create our three entities (Author, Category and Book), link them together, and create the tables with migrations.\nWhat you\u0026#39;ll learn\nConfigure the MySQL connection in Symfony Create entities with make:entity, field by field Link entities: ManyToOne and ManyToMany Turn entities into tables with migrations Configuring the Database The connection is configured in the .env file at the root of the project. Symfony already ships with a few commented examples (SQLite, MySQL, MariaDB, PostgreSQL). We use MySQL, so we uncomment the MySQL line and comment out the others.\nThe URL follows this pattern:\nmysql://USER:PASSWORD@HOST:PORT/DATABASE_NAME?serverVersion=VERSION With WAMP, the user is root and there is no password. Our database is called minibib:\nDATABASE_URL=\u0026#34;mysql://root:@127.0.0.1:3306/minibib?serverVersion=8.0.32\u0026amp;charset=utf8mb4\u0026#34; Creating the Database symfony console doctrine:database:create # short version: symfony console d:d:c Refresh phpMyAdmin: the empty minibib database is there.\nWhat Is an Entity? An entity is a PHP class that represents a table in the database. Each property becomes a column. Symfony also generates a repository for each entity: the class responsible for all the queries on that table.\nWe create entities with the Maker command, which guides you step by step:\nsymfony console make:entity Tip: when asked for a field type, type ? to see every type Doctrine supports.\nThe Author Entity We answer the questions like this:\nField Type Nullable firstName string (255) yes lastName string (255) yes biography text yes authorSlug string (255) yes birthday date_immutable yes The biography uses text rather than string, because it will be longer than 255 characters. The slug will be used in URLs later on.\nThe Maker writes each field directly into src/Entity/Author.php, with its Doctrine attributes, getters and setters:\n#[ORM\\Entity(repositoryClass: AuthorRepository::class)] class Author { #[ORM\\Id] #[ORM\\GeneratedValue] #[ORM\\Column] private ?int $id = null; #[ORM\\Column(length: 255, nullable: true)] private ?string $firstName = null; #[ORM\\Column(length: 255, nullable: true)] private ?string $lastName = null; #[ORM\\Column(type: Types::TEXT, nullable: true)] private ?string $biography = null; #[ORM\\Column(length: 255, nullable: true)] private ?string $authorSlug = null; #[ORM\\Column(type: Types::DATE_IMMUTABLE, nullable: true)] private ?\\DateTimeImmutable $birthday = null; // getters and setters... } Migrations: From Entity to Table Creating the class doesn\u0026rsquo;t create the table. For that we use two commands:\nsymfony console make:migration symfony console doctrine:migrations:migrate make:migration generates a file in migrations/ containing the SQL queries needed to create the table and its columns. doctrine:migrations:migrate runs that file against the database. Refresh phpMyAdmin: the author table is there with all its columns.\nThe Category Entity Same command, with a single field: categoryName (string, 255).\nThe Book Entity This is the most important entity of the project:\nField Type Why title string The book title summary text A long description bookSlug string For URLs isArchived boolean Symfony detects the is prefix and suggests boolean bookFileName / bookFilePath string The PDF file coverImageName / coverImagePath string The cover image Relations Still in make:entity, we add two fields of type relation:\nauthor → Author, ManyToOne: each book has one author, but an author can write several books. We also accept the suggestion to add a books collection on Author, to get all the books of an author. categories → Category, ManyToMany: a book can have several categories, and a category contains several books. #[ORM\\ManyToOne(inversedBy: \u0026#39;books\u0026#39;)] private ?Author $author = null; /** * @var Collection\u0026lt;int, Category\u0026gt; */ #[ORM\\ManyToMany(targetEntity: Category::class, inversedBy: \u0026#39;books\u0026#39;)] private Collection $categories; Then we migrate again:\nsymfony console make:migration symfony console doctrine:migrations:migrate In the database we now have author, book, category, and book_category: the join table for the ManyToMany relation, created automatically by Doctrine.\nAuthor firstName lastName biography authorSlug birthday Book title summary bookSlug isArchived bookFileName coverImageName author categories Category categoryName 1 N ManyToOne N N ManyToMany book_category join table created by Doctrine Our three entities: a book has one author (ManyToOne) and several categories (ManyToMany, through the book_category table). These relationships are exactly the ones you\u0026rsquo;ll find in SQL. To understand what Doctrine creates behind the scenes, check the Tables, Relationships and Data Manipulation chapter of the SQL course.\nYour credentials don\u0026#39;t belong in .env\nThe .env file is committed to Git: everything you write there ends up on GitHub. For your local credentials, create a .env.local file instead. Git ignores it, and it overrides .env:\n# .env.local DATABASE_URL=\u0026#34;mysql://root:@127.0.0.1:3306/minibib?serverVersion=8.0.32\u0026amp;charset=utf8mb4\u0026#34; Keep a sample value in .env, without any real password.\nCommon mistake\nYour password contains @, : or /? Those characters mean something in the connection URL, and Doctrine can no longer parse it. Encode them: @ becomes %40, : becomes %3A, / becomes %2F.\nGoing further\nTo see which migrations have run and which are still pending:\nsymfony console doctrine:migrations:status You may come across doctrine:schema:update --force, which changes the database directly without a migration. It\u0026rsquo;s handy for a quick test, but avoid it in a real project: without a migration file, there\u0026rsquo;s no way to replay the changes on another machine or in production.\nRecap The database connection lives in DATABASE_URL in .env doctrine:database:create (or d:d:c) creates the database make:entity creates or updates an entity, field by field make:migration + doctrine:migrations:migrate turn entities into tables ManyToOne for book → author, ManyToMany for book ↔ categories Exercise · A publication date\nAdd an optional date field publishedAt to the Book entity, then create the column in the database.\nShow the solution symfony console make:entity Book # New property name: publishedAt # Field type: date_immutable # Can this field be null: yes symfony console make:migration symfony console doctrine:migrations:migrate Running make:entity on an existing entity simply adds new fields. Don\u0026rsquo;t forget the migration: that\u0026rsquo;s what creates the column.\nWhat\u0026rsquo;s Next Before going further, we\u0026rsquo;ll put the project on GitHub so our work is versioned and safe.\nThis is Chapter 3 of the Mini Library course. Follow along to build a complete Symfony 8 + EasyAdmin digital library application from scratch.\n","permalink":"https://naimidevslayer.com/en/cours/developpement-web/symfony-8/mini-bibliotheque/03-database-entities-migrations/","summary":"\u003cp\u003eOur app runs and has a template. Now it needs data. In this chapter we connect Symfony to a \u003cstrong\u003eMySQL database\u003c/strong\u003e, create our three entities (\u003cstrong\u003eAuthor\u003c/strong\u003e, \u003cstrong\u003eCategory\u003c/strong\u003e and \u003cstrong\u003eBook\u003c/strong\u003e), link them together, and create the tables with \u003cstrong\u003emigrations\u003c/strong\u003e.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/8kHEvhm62js?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eConfigure the MySQL connection in Symfony\u003c/li\u003e\n\u003cli\u003eCreate entities with \u003ccode\u003emake:entity\u003c/code\u003e, field by field\u003c/li\u003e\n\u003cli\u003eLink entities: ManyToOne and ManyToMany\u003c/li\u003e\n\u003cli\u003eTurn entities into tables with migrations\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"configuring-the-database\"\u003eConfiguring the Database\u003c/h2\u003e\n\u003cp\u003eThe connection is configured in the \u003ccode\u003e.env\u003c/code\u003e file at the root of the project. Symfony already ships with a few commented examples (SQLite, MySQL, MariaDB, PostgreSQL). We use MySQL, so we uncomment the MySQL line and comment out the others.\u003c/p\u003e","title":"Mini Library Course #3: Database, Entities \u0026 Migrations with Doctrine"},{"content":"In the previous chapter, the project already existed on the server. Here, we start from an empty folder: we initialize Git, then send the project to GitHub.\nWhat you\u0026#39;ll learn\nTurn an existing folder into a Git repository with git init Create the repository on GitHub and understand .gitignore Link your project to the repository with git remote Make the first commit and the first push 1. Initialize Git: git init Create a folder with a first file, then initialize Git inside it:\nmkdir git-demo cd git-demo echo \u0026#34;test\u0026#34; \u0026gt; test.txt git init # Initialized empty Git repository in …/git-demo/.git/ Git creates a hidden .git folder. That\u0026rsquo;s where it stores the project\u0026rsquo;s whole history and configuration. Don\u0026rsquo;t delete it: without it, the folder is no longer a Git repository.\n2. Create the repository on GitHub On GitHub, click New repository:\nName: git-demo; Visibility: public or private; README, .gitignore, license: leave them empty, since your project already exists locally. What\u0026rsquo;s .gitignore? Some files must never go to GitHub: local config files, passwords, downloaded dependencies… Just list them in a .gitignore file at the root of the project, and Git will ignore them:\n.env.local /vendor/ /node_modules/ You can edit those files freely on your machine: they\u0026rsquo;ll never be sent.\n3. Link the project to GitHub: git remote Once the repository is created, GitHub shows the commands to run. We add the remote, meaning the address of the remote repository:\ngit remote add origin https://github.com/\u0026lt;user\u0026gt;/git-demo.git Check it:\ngit remote -v # origin https://github.com/\u0026lt;user\u0026gt;/git-demo.git (fetch) # origin https://github.com/\u0026lt;user\u0026gt;/git-demo.git (push) fetch: the address used to get data; push: the address used to send it. 4. First commit With the commands from the previous chapter:\ngit status git add . git commit -m \u0026#34;First commit\u0026#34; 5. The default branch After git init, Git creates a default branch, master here. To work on another branch, you already know how: git checkout -b \u0026lt;name\u0026gt;. In this example, we push straight to master.\nGitHub uses main as the default name. To make your new projects start on main: git config --global init.defaultBranch main.\n6. First push git push # fatal: The current branch master has no upstream branch. That\u0026rsquo;s expected: on GitHub, we only created the repository, without any branch. Git gives you the exact command:\ngit push --set-upstream origin master Refresh the GitHub page: your file is there, on the master branch. Get into the habit of reading Git\u0026rsquo;s messages: very often, they tell you exactly what to do.\nThe two first-push errors\n\u0026ldquo;remote origin already exists\u0026rdquo;: the project is already linked to a repository (an old one, for example). To change the URL instead of adding another:\ngit remote set-url origin https://github.com/\u0026lt;user\u0026gt;/\u0026lt;project\u0026gt;.git \u0026ldquo;src refspec main does not match any\u0026rdquo;: the main branch doesn\u0026rsquo;t exist yet. Either you haven\u0026rsquo;t made any commit (a branch only exists from its first commit), or your branch is called master. Check with git branch, then push the right branch.\nWatch out\nSet up .gitignore before the first git add .. A file that\u0026rsquo;s already committed stays tracked even if you add it to .gitignore afterwards: you then need to untrack it with git rm --cached \u0026lt;file\u0026gt;. And if it was a password file, consider those passwords compromised and change them.\nRecap Command Role git init Turn a folder into a Git repository .gitignore List the files Git should ignore git remote add origin \u0026lt;url\u0026gt; Link the project to a remote repository git remote -v Show remote repositories git push --set-upstream origin \u0026lt;branch\u0026gt; First push of a branch Exercise · Ignore the right files\nYour project has a node_modules/ folder, a .env file with passwords and some *.log files. Write the .gitignore.\nShow the solution node_modules/ .env *.log A name ending with / means a folder, and * matches any sequence of characters. Then check with git status: those files must no longer show up.\nWhat\u0026rsquo;s Next In the next chapter, we discover a command that saves the day when you have to switch tasks urgently: git stash.\nThis is Chapter 4 of the Git in Practice course. Follow along to learn how to use Git every day and as a team.\n","permalink":"https://naimidevslayer.com/en/cours/outils/git/git-en-pratique/04-git-init-github/","summary":"\u003cp\u003eIn the previous chapter, the project already existed on the server. Here, we start from an empty folder: we initialize Git, then send the project to \u003cstrong\u003eGitHub\u003c/strong\u003e.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/WzMF_k-1cvc?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eTurn an existing folder into a Git repository with \u003ccode\u003egit init\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003eCreate the repository on GitHub and understand \u003ccode\u003e.gitignore\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003eLink your project to the repository with \u003ccode\u003egit remote\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003eMake the first commit and the first push\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"1-initialize-git-git-init\"\u003e1. Initialize Git: \u003ccode\u003egit init\u003c/code\u003e\u003c/h2\u003e\n\u003cp\u003eCreate a folder with a first file, then initialize Git inside it:\u003c/p\u003e","title":"Git in Practice #4: git init and Your First Push to GitHub"},{"content":"A database without tables is an empty box. In this chapter, we create and modify tables, link them together, then insert, update and delete data.\nWhat you\u0026#39;ll learn\nCreate, modify and delete tables Link tables: one to one, one to many, many to many Name your constraints Insert, update and delete data safely Anatomy of a table Take a user table with four columns:\nColumn Type Note id INT Unique identifier: no two rows can share it name VARCHAR(255) String of up to 255 characters birthday DATE A date city VARCHAR(255) String To create a table, you define each field\u0026rsquo;s name, type and any rules (required, unique, default value…).\nCreating a table: CREATE TABLE CREATE TABLE user ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) DEFAULT NULL, birthday DATE NOT NULL, city VARCHAR(255) NOT NULL DEFAULT \u0026#39;Tunis\u0026#39; ); Keyword Role NOT NULL The field is required AUTO_INCREMENT MySQL assigns 1, 2, 3… automatically on insert PRIMARY KEY The primary key: each row\u0026rsquo;s unique identifier DEFAULT The value used when none is given on insert In phpMyAdmin, open your database, go to the SQL tab, paste the query and run it: the user table appears. You can also create a table straight from the interface, by choosing the number of columns, then each column\u0026rsquo;s name, type and options.\nRenaming and deleting a table RENAME TABLE user TO utilisateur; DROP TABLE utilisateur; Modifying columns: ALTER TABLE -- Add a column ALTER TABLE user ADD country VARCHAR(100); -- Remove a column ALTER TABLE user DROP COLUMN country; -- Change a column\u0026#39;s type ALTER TABLE user MODIFY city VARCHAR(100); -- Rename a column (restating its type) ALTER TABLE user CHANGE city town VARCHAR(100); Try them yourself on your table: it\u0026rsquo;s the best way to remember them.\nRelationships between tables We\u0026rsquo;re working with a relational database: tables are linked to each other. Two tables are linked through a foreign key (FOREIGN KEY), a column that references the primary key of another table.\nOne to one user 1 1 passport One to many client 1 N commande foreign key on the \u0026#34;many\u0026#34; side Many to many student 1 N inscription N 1 course junction table The three kinds of relationships, and where the foreign key goes in each case. One to one Example: a person has a single passport, and a passport belongs to a single person.\nCREATE TABLE user ( user_id INT PRIMARY KEY, first_name VARCHAR(100), last_name VARCHAR(100) ); CREATE TABLE passport ( user_id INT PRIMARY KEY, passport_number VARCHAR(50), expiration_date DATE, FOREIGN KEY (user_id) REFERENCES user(user_id) ); Here, user_id is both the primary key and the foreign key of passport: one person can\u0026rsquo;t have two passports.\nA variant: a primary key made of two columns, the user and the passport number. Their combination must be unique:\nCREATE TABLE passport ( user_id INT, passport_number VARCHAR(50), FOREIGN KEY (user_id) REFERENCES user(user_id), PRIMARY KEY (user_id, passport_number) ); One to many Example: a customer can place several orders, but an order belongs to a single customer. Read the other way round, it\u0026rsquo;s many to one.\nCREATE TABLE client ( client_id INT PRIMARY KEY, name VARCHAR(100) ); CREATE TABLE commande ( commande_id INT PRIMARY KEY, client_id INT, FOREIGN KEY (client_id) REFERENCES client(client_id) ); The foreign key goes on the \u0026ldquo;many\u0026rdquo; side: each order points to its customer.\nMany to many Example: a student can take several courses, and a course can be taken by several students.\nHere, a foreign key in one of the two tables isn\u0026rsquo;t enough. You need a junction table, with one row per student / course pair:\nCREATE TABLE student ( student_id INT PRIMARY KEY, name VARCHAR(100) ); CREATE TABLE course ( course_id INT PRIMARY KEY, title VARCHAR(100) ); CREATE TABLE inscription ( inscription_id INT PRIMARY KEY, student_id INT, course_id INT, FOREIGN KEY (student_id) REFERENCES student(student_id), FOREIGN KEY (course_id) REFERENCES course(course_id) ); Two options for the junction table:\nit holds only the two foreign keys, and their combination is the primary key; it needs extra information, like an enrollment ID here. It then gets its own primary key. Constraints (CONSTRAINT) A constraint is a rule applied to a column or a set of columns, to guarantee the integrity and consistency of the data. You can name them with CONSTRAINT:\nCREATE TABLE commande ( commande_id INT, client_id INT, CONSTRAINT pk_commande PRIMARY KEY (commande_id), CONSTRAINT fk_commande_client FOREIGN KEY (client_id) REFERENCES client(client_id) ); Both syntaxes (named or not) work. Naming your constraints mostly helps you find and drop them later.\nManipulating data Insert: INSERT INTO INSERT INTO user (name, birthday, city) VALUES (\u0026#39;Safe\u0026#39;, \u0026#39;1995-04-12\u0026#39;, \u0026#39;Paris\u0026#39;); Listing the fields you fill avoids nasty surprises: if a country column with DEFAULT NULL is added later, this query keeps working.\nUpdate: UPDATE UPDATE user SET birthday = \u0026#39;1995-05-01\u0026#39; WHERE name = \u0026#39;Safe\u0026#39;; SET says which column to change, WHERE says which rows. Careful: if 50 rows are named \u0026ldquo;Safe\u0026rdquo;, all 50 get updated. To target a single row, use its ID: WHERE id = 3.\nDelete: DELETE DELETE FROM user WHERE name = \u0026#39;Safe\u0026#39;; ⚠️ Without WHERE, UPDATE and DELETE apply to the whole table. Always double-check your condition before running them.\nThe safety net: transactions\nBefore a risky UPDATE or DELETE, open a transaction. You check the result, then confirm with COMMIT… or undo everything with ROLLBACK:\nSTART TRANSACTION; DELETE FROM user WHERE city = \u0026#39;Paris\u0026#39;; SELECT COUNT(*) FROM user; -- is that the expected result? ROLLBACK; -- undoes the deletion (or COMMIT; to keep it) And two simple habits: first run a SELECT with the same WHERE to see which rows are affected, and write the WHERE before the rest of the query.\nEmpty a table: TRUNCATE TRUNCATE TABLE user; TRUNCATE removes all the table\u0026rsquo;s content at once, like a DELETE without WHERE, and also resets the AUTO_INCREMENT counter.\nWhat happens to an order when its customer is deleted?\nBy default, MySQL refuses to delete a customer who still has orders: the foreign key protects data consistency. You can pick another behavior with ON DELETE:\nFOREIGN KEY (client_id) REFERENCES client(client_id) ON DELETE CASCADE Option When the customer is deleted… (nothing) or RESTRICT … the deletion is refused CASCADE … their orders are deleted too SET NULL … their orders stay, with client_id set to NULL CASCADE is handy, but use it with care: a single deletion can wipe out many rows in a chain.\nAlso note: TRUNCATE is refused on a table referenced by a foreign key (error 1701). In that case, use DELETE instead.\nGoing further\nThese are exactly the relationships we build with Doctrine in the Mini Library course: a book has one author (ManyToOne) and several categories (ManyToMany, with a junction table).\nRecap Command Role CREATE TABLE Create a table RENAME TABLE … TO … Rename a table DROP TABLE Delete a table ALTER TABLE … ADD / DROP / MODIFY / CHANGE Modify columns FOREIGN KEY … REFERENCES Link two tables INSERT, UPDATE, DELETE, TRUNCATE Manipulate data Exercise · Authors and books\nCreate two tables: author (id, name) and book (id, title, author_id). An author can write several books. Add the foreign key, then insert one author and two of their books.\nShow the solution CREATE TABLE author ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT NULL ); CREATE TABLE book ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255) NOT NULL, author_id INT NOT NULL, CONSTRAINT fk_book_author FOREIGN KEY (author_id) REFERENCES author(id) ); INSERT INTO author (name) VALUES (\u0026#39;Victor Hugo\u0026#39;); INSERT INTO book (title, author_id) VALUES (\u0026#39;Les Misérables\u0026#39;, 1), (\u0026#39;The Hunchback of Notre-Dame\u0026#39;, 1); It\u0026rsquo;s a one-to-many relationship: the foreign key goes on the \u0026ldquo;many\u0026rdquo; side, so in book. Then try inserting a book with author_id = 99: MySQL refuses, since that author doesn\u0026rsquo;t exist.\nWhat\u0026rsquo;s Next Our tables are ready and filled. In the next chapter, we learn to query the data with SELECT.\nThis is Chapter 4 of the SQL from Zero to Pro course. Follow along to learn SQL with MySQL, from the basics to joins.\n","permalink":"https://naimidevslayer.com/en/cours/bases-de-donnees/mysql/sql-de-zero-a-pro/04-tables-relations-donnees/","summary":"\u003cp\u003eA database without tables is an empty box. In this chapter, we create and modify \u003cstrong\u003etables\u003c/strong\u003e, \u003cstrong\u003elink them together\u003c/strong\u003e, then \u003cstrong\u003einsert, update and delete\u003c/strong\u003e data.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/8XI37ht3QNE?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eCreate, modify and delete tables\u003c/li\u003e\n\u003cli\u003eLink tables: one to one, one to many, many to many\u003c/li\u003e\n\u003cli\u003eName your constraints\u003c/li\u003e\n\u003cli\u003eInsert, update and delete data safely\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"anatomy-of-a-table\"\u003eAnatomy of a table\u003c/h2\u003e\n\u003cp\u003eTake a \u003ccode\u003euser\u003c/code\u003e table with four columns:\u003c/p\u003e","title":"SQL from Zero to Pro #4: Tables, Relationships and Data Manipulation"},{"content":"Before adding new features, we take a moment to push our code to GitHub. Versioning your work regularly is a good habit: it keeps a clean history, lets you go back if something breaks, and protects the work already done.\nWhat you\u0026#39;ll learn\nCreate a GitHub repository and link your Symfony project to it Make your first commit and push it to main Know which files must never go to GitHub Creating the Repository We use GitHub here, but GitLab or Bitbucket work the same way.\nClick New to create a repository. Name: same as the project, minibib. Visibility: public, so you can browse the code alongside the videos. README: no. .gitignore: no, Symfony already created one. License: not for now. Click Create repository. GitHub then shows every command needed to link a local project.\nLinking the Project to GitHub First, check whether the project already has a remote:\ngit remote -v Nothing yet. We add the one GitHub gave us:\ngit remote add origin https://github.com/\u0026lt;your-username\u0026gt;/minibib.git git remote -v # origin https://github.com/\u0026lt;your-username\u0026gt;/minibib.git (fetch) # origin https://github.com/\u0026lt;your-username\u0026gt;/minibib.git (push) Staging and Committing See which files changed:\ngit status Add them, either one by one with git add \u0026lt;file\u0026gt;, or all at once:\ngit add . git status # the files are now green Then commit with a short message:\ngit commit -m \u0026#34;first commit\u0026#34; Pushing to the main Branch Check which branch you\u0026rsquo;re on:\ngit branch # * master GitHub uses main as its default branch. Rather than dealing with master later (when deploying, for example), we rename it now:\ngit branch -M main git push origin main Refresh the repository page: the project is online.\nNotice the vendor/ folder isn\u0026rsquo;t there. That\u0026rsquo;s on purpose: it\u0026rsquo;s listed in .gitignore. Never push vendor/. Anyone can rebuild it with composer install.\nWhat must never be pushed\nThe .gitignore created by Symfony already excludes the essentials: /vendor/, /var/ (cache and logs) and .env.local, where your real credentials live. Before your first git add ., take a look at git status: if a config file with a password shows up, add it to .gitignore before committing. Once pushed, a secret stays in the history, even if you delete the file later.\nCommon mistake\nGitHub rejects your password on git push? That\u0026rsquo;s expected: since 2021, GitHub no longer accepts your account password on the command line. Use a personal access token (Settings → Developer settings → Personal access tokens) instead of the password, or set up an SSH key. The easiest way on Windows: let Git Credential Manager, installed with Git, open the sign-in in your browser.\nGoing further\nGit deserves a course of its own, and it has one: Git in Practice, from branches to pull requests.\nRecap git remote add origin \u0026lt;url\u0026gt; links the local project to GitHub git add . → git commit -m \u0026quot;...\u0026quot; → git push origin main git branch -M main renames master to main vendor/ stays out of Git Exercise · A second commit\nChange your home page title, then save that change in a new commit and push it to GitHub. Then check that your history contains two commits.\nShow the solution git status git add templates/home/index.html.twig git commit -m \u0026#34;Change the home page title\u0026#34; git push git log --oneline # a1b2c3d Change the home page title # 9f8e7d6 first commit Since main is already linked to the server after the first push, a plain git push is enough.\nWhat\u0026rsquo;s Next Time for the admin side: we\u0026rsquo;ll install EasyAdmin.\nThis is Chapter 4 of the Mini Library course. Follow along to build a complete Symfony 8 + EasyAdmin digital library application from scratch.\n","permalink":"https://naimidevslayer.com/en/cours/developpement-web/symfony-8/mini-bibliotheque/04-git-github/","summary":"\u003cp\u003eBefore adding new features, we take a moment to \u003cstrong\u003epush our code to GitHub\u003c/strong\u003e. Versioning your work regularly is a good habit: it keeps a clean history, lets you go back if something breaks, and protects the work already done.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/rQzQ94pwWms?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e","title":"Mini Library Course #4: Version Your Symfony Project with Git \u0026 GitHub"},{"content":"You\u0026rsquo;re in the middle of a change and need to switch branches urgently? Or you want to undo your changes, but not for good? That\u0026rsquo;s what git stash is for.\nWhat you\u0026#39;ll learn\nSet work in progress aside with git stash List, restore and delete your stashes Choose between apply and pop What git stash does git stash takes your uncommitted changes (staged with git add or not), sets them aside for later, and gives you back a clean working copy, as it was at the last commit.\nThe problem You\u0026rsquo;re on the test branch, and you\u0026rsquo;ve changed three files. Now:\neither you need to switch to develop for another task; or you want to remove those changes for now, without losing them. Without stash, you\u0026rsquo;d have to undo your changes by hand, file by file, and redo them later. With stash, it\u0026rsquo;s one command.\nSet changes aside git stash # Saved working directory and index state WIP on test: … git status # nothing to commit, working tree clean All your changes are saved in the stash stack, and your branch is clean. You can switch branches safely.\nNew files (not tracked by Git) are not stashed by default. To include them: git stash -u.\nList your stashes git stash list # stash@{0}: WIP on test: … # stash@{1}: WIP on test: … The most recent one is always stash@{0}.\nGet your changes back: apply or pop # Re-apply the last stash, and KEEP it in the list git stash apply # Re-apply the last stash, and REMOVE it from the list git stash pop Command Re-applies the changes Keeps the stash in the list git stash apply ✅ ✅ git stash pop ✅ ❌ To use a specific stash rather than the last one, give its index:\ngit stash apply stash@{1} Delete a stash: drop # Delete the last stash git stash drop # Delete a specific stash git stash drop stash@{1} So there are two ways to do the same thing:\ngit stash apply then git stash drop; or straight away git stash pop. Key takeaway git stash is very handy when you work on several branches at once: you set your work in progress aside, handle the urgent task elsewhere, then pick up exactly where you left off.\nName your stashes\nAfter three stashes, WIP on feature/1 doesn\u0026rsquo;t tell you much. Add a message:\ngit stash push -m \u0026#34;half-done contact form\u0026#34; git stash list # stash@{0}: On feature/1: half-done contact form A conflict on pop\nIf your changes clash with the current code, git stash pop stops on a conflict, just like a merge. Don\u0026rsquo;t panic: in that case Git keeps the stash in the list (\u0026ldquo;The stash entry is kept in case you need it again\u0026rdquo;). Resolve the conflict in your files, then delete the stash with git stash drop once everything is fine.\nExercise · An emergency mid-task\nYou\u0026rsquo;re editing index.html and have created a new contact.html file, when you\u0026rsquo;re asked for an urgent fix on main. Set everything aside, switch branches, then come back and restore your work.\nShow the solution git stash -u # -u: includes the new contact.html file git checkout main # … fix, commit, push … git checkout feature/contact git stash pop Without -u, contact.html (untracked by Git) would have stayed in your folder and followed you onto main.\nWhat\u0026rsquo;s Next In the next chapter: how to make the perfect commit.\nThis is Chapter 5 of the Git in Practice course. Follow along to learn how to use Git every day and as a team.\n","permalink":"https://naimidevslayer.com/en/cours/outils/git/git-en-pratique/05-git-stash/","summary":"\u003cp\u003eYou\u0026rsquo;re in the middle of a change and need to switch branches urgently? Or you want to undo your changes, but not for good? That\u0026rsquo;s what \u003cstrong\u003e\u003ccode\u003egit stash\u003c/code\u003e\u003c/strong\u003e is for.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/9ESGvO456Lg?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eSet work in progress aside with \u003ccode\u003egit stash\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003eList, restore and delete your stashes\u003c/li\u003e\n\u003cli\u003eChoose between \u003ccode\u003eapply\u003c/code\u003e and \u003ccode\u003epop\u003c/code\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"what-git-stash-does\"\u003eWhat \u003ccode\u003egit stash\u003c/code\u003e does\u003c/h2\u003e\n\u003cp\u003e\u003ccode\u003egit stash\u003c/code\u003e takes your \u003cstrong\u003euncommitted changes\u003c/strong\u003e (staged with \u003ccode\u003egit add\u003c/code\u003e or not), \u003cstrong\u003esets them aside\u003c/strong\u003e for later, and gives you back a \u003cstrong\u003eclean\u003c/strong\u003e working copy, as it was at the last commit.\u003c/p\u003e","title":"Git in Practice #5: Setting Work Aside with git stash"},{"content":"Let\u0026rsquo;s tackle one of the most fundamental concepts in SQL: SELECT queries. With them, you can extract data, filter results, sort them, and even run calculations.\nWhat you\u0026#39;ll learn\nRead data with SELECT Filter, group, sort and paginate with clauses Compute with aggregate functions Understand the order in which MySQL runs a query Basic syntax -- Get some columns SELECT name, city FROM user; -- Get every column SELECT * FROM user; Both queries return every row of the table. To filter, organize or group, we add clauses.\nClauses Clause Role Example WHERE Filter rows WHERE city = 'Paris' GROUP BY Group rows that share a value GROUP BY city HAVING Filter groups, after grouping HAVING COUNT(*) \u0026gt; 30 ORDER BY Sort, ascending (ASC) or descending (DESC) ORDER BY name ASC, birthday DESC LIMIT Cap the number of results LIMIT 5 OFFSET Skip a number of rows LIMIT 5 OFFSET 15 For example, to show 5 users starting from the 16th row:\nSELECT * FROM user LIMIT 5 OFFSET 15; Aggregate functions They run calculations on a column and go in the SELECT:\nFunction Role Example COUNT() Count rows SELECT COUNT(*) FROM user; AVG() Average SELECT AVG(nb_stars) FROM user; SUM() Sum SELECT SUM(nb_like) FROM post; MAX() Maximum value SELECT MAX(nb_stars) FROM user; MIN() Minimum value SELECT MIN(nb_stars) FROM user; A complete example SELECT categorie, AVG(prix) AS prix_moyen FROM produit WHERE prix \u0026gt; 50 GROUP BY categorie HAVING AVG(prix) \u0026gt; 100 ORDER BY prix_moyen DESC LIMIT 5; Let\u0026rsquo;s read it line by line (produit = product, prix = price, categorie = category):\nSELECT categorie, AVG(prix) AS prix_moyen: show the category and the average price. AS gives the column an alias, so it reads prix_moyen instead of AVG(prix). FROM produit: read the produit table. WHERE prix \u0026gt; 50: keep only products priced above 50. GROUP BY categorie: group the results by category. HAVING AVG(prix) \u0026gt; 100: keep only categories whose average price is above 100. ORDER BY prix_moyen DESC: sort by average price, highest first, reusing the alias. LIMIT 5: keep the first 5 rows. WHERE or HAVING? WHERE filters rows before grouping, HAVING filters groups after.\nThe order in which MySQL reads your query\nWe write SELECT first, but MySQL runs it almost last:\nFROM: which table? WHERE: which rows? GROUP BY: which groups? HAVING: which groups to keep? SELECT: which columns, and their aliases ORDER BY: in what order? LIMIT / OFFSET: how many? That explains two rules that surprise beginners: you can use the prix_moyen alias in ORDER BY (run after SELECT), but not in WHERE (run before). And it\u0026rsquo;s why WHERE can\u0026rsquo;t contain AVG(): the groups don\u0026rsquo;t exist yet.\nCommon mistake\nError 1055 \u0026ldquo;isn\u0026rsquo;t in GROUP BY\u0026rdquo;? With GROUP BY, every column in SELECT must be either in the GROUP BY or inside an aggregate function. MySQL rejects this query:\nSELECT city, name, COUNT(*) FROM user GROUP BY city; Makes sense: one city groups 34 users, so MySQL can\u0026rsquo;t guess which name to show. Remove name, or add it to the GROUP BY.\nIndexes and performance On a table with thousands of rows, searches need to stay fast. Indexes speed up searches on a column:\nCREATE INDEX idx_user_city ON user (city); The primary key is itself a special index that guarantees every value is unique. As we saw, it can also span several columns.\nHands-on Take a tuto_sql database with two tables:\nuser: id, name, birthday, city post: id, title, content, user_id, created_at, nb_like A user can write several posts, and a post belongs to a single user (one-to-many through user_id).\nUsers who live in Paris:\nSELECT * FROM user WHERE city = \u0026#39;Paris\u0026#39;; How many are there?\nSELECT COUNT(*) AS nb_user FROM user WHERE city = \u0026#39;Paris\u0026#39;; -- nb_user: 34 Number of users per city:\nSELECT city, COUNT(*) AS nb_user FROM user GROUP BY city; -- Madrid 33, Paris 34, Tunis 33 Only cities with 33 users:\nSELECT city, COUNT(*) AS nb_user FROM user GROUP BY city HAVING COUNT(*) = 33; -- Madrid, Tunis Average likes on user 1\u0026rsquo;s posts:\nSELECT AVG(nb_like), SUM(nb_like), COUNT(*) FROM post WHERE user_id = 1; -- 583.0000, 1749, 3 The average is indeed the sum divided by the number of posts: 1749 / 3 = 583. MySQL always returns an average with decimals (583.0000). For a result without decimals, add ROUND():\nSELECT ROUND(AVG(nb_like)) FROM post WHERE user_id = 1; -- 583 phpMyAdmin also lets you run simple searches without writing SQL. But in this course we write real queries: that\u0026rsquo;s what you\u0026rsquo;ll use in your code.\nSearching for part of a text: LIKE\nTo find users whose name starts with \u0026ldquo;Sa\u0026rdquo;:\nSELECT * FROM user WHERE name LIKE \u0026#39;Sa%\u0026#39;; % matches any sequence of characters (even an empty one), _ matches exactly one character. '%dev%' finds \u0026ldquo;dev\u0026rdquo; anywhere in the text, but watch out: a % at the start prevents MySQL from using the column\u0026rsquo;s index.\nExercise · The users\u0026#39; podium\nUsing the post table, show the 3 users (their user_id) with the most likes in total, with that total, from highest to lowest.\nShow the solution SELECT user_id, SUM(nb_like) AS total_likes FROM post GROUP BY user_id ORDER BY total_likes DESC LIMIT 3; We group by user, add up each group\u0026rsquo;s likes, sort on the alias, and keep the first three. To show their name instead of their user_id, you\u0026rsquo;ll need a join: see chapter 7.\nWhat\u0026rsquo;s Next In the next chapter, we move on to advanced SQL with subqueries. And we\u0026rsquo;ll do many more examples in the exercise chapters.\nThis is Chapter 5 of the SQL from Zero to Pro course. Follow along to learn SQL with MySQL, from the basics to joins.\n","permalink":"https://naimidevslayer.com/en/cours/bases-de-donnees/mysql/sql-de-zero-a-pro/05-select/","summary":"\u003cp\u003eLet\u0026rsquo;s tackle one of the most fundamental concepts in SQL: \u003cstrong\u003e\u003ccode\u003eSELECT\u003c/code\u003e\u003c/strong\u003e queries. With them, you can extract data, filter results, sort them, and even run calculations.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/BsVtkAheFG0?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eRead data with \u003ccode\u003eSELECT\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003eFilter, group, sort and paginate with clauses\u003c/li\u003e\n\u003cli\u003eCompute with aggregate functions\u003c/li\u003e\n\u003cli\u003eUnderstand the order in which MySQL runs a query\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"basic-syntax\"\u003eBasic syntax\u003c/h2\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" class=\"chroma\"\u003e\u003ccode class=\"language-sql\" data-lang=\"sql\"\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003e\u003cspan class=\"c1\"\u003e-- Get some columns\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003e\u003cspan class=\"c1\"\u003e\u003c/span\u003e\u003cspan class=\"k\"\u003eSELECT\u003c/span\u003e\u003cspan class=\"w\"\u003e \u003c/span\u003e\u003cspan class=\"n\"\u003ename\u003c/span\u003e\u003cspan class=\"p\"\u003e,\u003c/span\u003e\u003cspan class=\"w\"\u003e \u003c/span\u003e\u003cspan class=\"n\"\u003ecity\u003c/span\u003e\u003cspan class=\"w\"\u003e \u003c/span\u003e\u003cspan class=\"k\"\u003eFROM\u003c/span\u003e\u003cspan class=\"w\"\u003e \u003c/span\u003e\u003cspan class=\"k\"\u003euser\u003c/span\u003e\u003cspan class=\"p\"\u003e;\u003c/span\u003e\u003cspan class=\"w\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003e\u003cspan class=\"w\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003e\u003cspan class=\"w\"\u003e\u003c/span\u003e\u003cspan class=\"c1\"\u003e-- Get every column\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003e\u003cspan class=\"c1\"\u003e\u003c/span\u003e\u003cspan class=\"k\"\u003eSELECT\u003c/span\u003e\u003cspan class=\"w\"\u003e \u003c/span\u003e\u003cspan class=\"o\"\u003e*\u003c/span\u003e\u003cspan class=\"w\"\u003e \u003c/span\u003e\u003cspan class=\"k\"\u003eFROM\u003c/span\u003e\u003cspan class=\"w\"\u003e \u003c/span\u003e\u003cspan class=\"k\"\u003euser\u003c/span\u003e\u003cspan class=\"p\"\u003e;\u003c/span\u003e\u003cspan class=\"w\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eBoth queries return \u003cstrong\u003eevery row\u003c/strong\u003e of the table. To filter, organize or group, we add \u003cstrong\u003eclauses\u003c/strong\u003e.\u003c/p\u003e","title":"SQL from Zero to Pro #5: Querying Data with SELECT"},{"content":"Now we start the administration side of our library. We\u0026rsquo;ll use EasyAdminBundle, which builds a complete back office very quickly: CRUD screens, entity management, and a lot of saved time.\nWhat you\u0026#39;ll learn\nInstall EasyAdmin 5 with Composer Understand what Symfony Flex adds to the project Generate the admin dashboard with make:admin:dashboard Protect access to /admin Requirements EasyAdmin needs:\nPHP 8.2 or higher Symfony 6.4 or higher (we\u0026rsquo;re on Symfony 8) Doctrine ORM (already installed with --webapp) Installation In the VS Code terminal:\ncomposer require easycorp/easyadmin-bundle What Got Added Once Composer and Symfony Flex are done, here\u0026rsquo;s what changed:\nFile What it is composer.json EasyAdmin added (version 5.x) config/packages/twig_component.yaml Twig Components: not part of EasyAdmin itself, but required to render its interface config/routes/easyadmin.yaml Loads the admin routes config/bundles.php Registers TwigComponentBundle and EasyAdminBundle Here is the route file:\n# config/routes/easyadmin.yaml easyadmin: resource: . type: easyadmin.routes New Console Commands EasyAdmin also adds Maker commands that generate classes for us. List them with:\nsymfony console You\u0026rsquo;ll find, among others:\nmake:admin:dashboard make:admin:crud Generating the Dashboard symfony console make:admin:dashboard We keep the default answers:\nClass name: DashboardController Directory: src/Controller/Admin/ The command creates src/Controller/Admin/DashboardController.php. Inside you\u0026rsquo;ll find:\nthe /admin route, declared with the #[AdminDashboard] attribute an index() method with three commented options for what the dashboard should display configureDashboard(), which sets the dashboard title configureMenuItems(), which builds the side menu, starting with a Dashboard item and its Font Awesome icon #[AdminDashboard(routePath: \u0026#39;/admin\u0026#39;, routeName: \u0026#39;admin\u0026#39;)] class DashboardController extends AbstractDashboardController { public function index(): Response { return parent::index(); } public function configureDashboard(): Dashboard { return Dashboard::new() -\u0026gt;setTitle(\u0026#39;Minibib\u0026#39;); } public function configureMenuItems(): iterable { yield MenuItem::linkToDashboard(\u0026#39;Dashboard\u0026#39;, \u0026#39;fa fa-home\u0026#39;); } } Opening the Admin Go to http://127.0.0.1:8000/admin instead of /home: you\u0026rsquo;ll see the \u0026ldquo;Welcome to EasyAdmin 5\u0026rdquo; page, with links to the documentation.\nYour admin is open to everyone\nRight now, anyone can visit /admin. Locally that\u0026rsquo;s fine, but before going live, the admin must be restricted to administrators. With Symfony\u0026rsquo;s Security component, one line in config/packages/security.yaml does it:\nsecurity: access_control: - { path: ^/admin, roles: ROLE_ADMIN } Or directly on the controller, with an attribute:\nuse Symfony\\Component\\Security\\Http\\Attribute\\IsGranted; #[IsGranted(\u0026#39;ROLE_ADMIN\u0026#39;)] #[AdminDashboard(routePath: \u0026#39;/admin\u0026#39;, routeName: \u0026#39;admin\u0026#39;)] class DashboardController extends AbstractDashboardController You also need users and a login page (make:user, then make:security:form-login): we\u0026rsquo;ll get there with the User entity.\nCommon mistake\n/admin returns a 404 right after installing? Clear the cache, then check that the route exists:\nsymfony console cache:clear symfony console debug:router | grep admin Recap composer require easycorp/easyadmin-bundle installs EasyAdmin Flex adds the routes, bundles and Twig Components automatically make:admin:dashboard generates the dashboard controller The admin lives at /admin Exercise · Customize the dashboard\nChange the dashboard title to \u0026ldquo;Mini Library\u0026rdquo; and add a \u0026ldquo;Catalog\u0026rdquo; section to the menu, below the Dashboard item.\nShow the solution public function configureDashboard(): Dashboard { return Dashboard::new() -\u0026gt;setTitle(\u0026#39;Mini Library\u0026#39;); } public function configureMenuItems(): iterable { yield MenuItem::linkToDashboard(\u0026#39;Dashboard\u0026#39;, \u0026#39;fa fa-home\u0026#39;); yield MenuItem::section(\u0026#39;Catalog\u0026#39;); } MenuItem::section() adds a heading to the menu: handy to group the CRUDs we\u0026rsquo;re about to create (books, authors, categories).\nWhat\u0026rsquo;s Next We\u0026rsquo;ll replace the welcome page with our own dashboard template.\nThis is Chapter 5 of the Mini Library course. Follow along to build a complete Symfony 8 + EasyAdmin digital library application from scratch.\n","permalink":"https://naimidevslayer.com/en/cours/developpement-web/symfony-8/mini-bibliotheque/05-install-easyadmin/","summary":"\u003cp\u003eNow we start the \u003cstrong\u003eadministration side\u003c/strong\u003e of our library. We\u0026rsquo;ll use \u003cstrong\u003eEasyAdminBundle\u003c/strong\u003e, which builds a complete back office very quickly: CRUD screens, entity management, and a lot of saved time.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/NOWUukA4NdA?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eInstall EasyAdmin 5 with Composer\u003c/li\u003e\n\u003cli\u003eUnderstand what Symfony Flex adds to the project\u003c/li\u003e\n\u003cli\u003eGenerate the admin dashboard with \u003ccode\u003emake:admin:dashboard\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003eProtect access to \u003ccode\u003e/admin\u003c/code\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"requirements\"\u003eRequirements\u003c/h2\u003e\n\u003cp\u003eEasyAdmin needs:\u003c/p\u003e","title":"Mini Library Course #5: Install EasyAdmin 5 in Symfony 8"},{"content":"What should you do before committing? Here\u0026rsquo;s a simple method for clean commits your teammates will understand right away.\nWhat you\u0026#39;ll learn\nReview your changes before committing Make commits that cover a single topic Write a clear commit message 1. List the changed files git status Check that no file was changed by mistake. If a file has nothing to do with this commit, don\u0026rsquo;t add it.\n2. Review the added code Go over each change (with git diff, covered in chapter 11) and look for:\nleftover debugging: a dump(), a die(), a console.log()…; useless spaces or line breaks, added by mistake or by your editor. Remove them and save: your commit should only contain real changes.\n3. One commit = one topic Sometimes, the same file holds two unrelated changes: one for this commit, another for a later one. Rather than temporarily deleting code and putting it back afterwards, Git has an option built for this:\ngit add -p Git shows you each block of changes (a \u0026ldquo;hunk\u0026rdquo;) and asks whether to stage it:\nKey Action y Yes, stage this block n No, keep it for later s Split the block into smaller pieces q Quit Then run git status again: the same file shows up both in the files ready to commit and in the modified files. That\u0026rsquo;s expected: one part goes into this commit, the other waits for the next one.\n4. Write a good message git commit -m \u0026#34;Add the sign-up page\u0026#34; Working with tickets (Jira, GitLab…)? The ticket number is often enough, since the ticket holds all the details. Otherwise, write a short, descriptive message, in a few words. Whoever reviews your pull request should understand right away what it\u0026rsquo;s about. -m saves you from opening a text editor to write the message: handy for a short message.\nThe result A perfect commit is:\nclean code, with nothing forgotten and nothing weird added; one topic per commit; a clear message. One file, two topics? git add -p\nYou fixed a bug and changed some text in the same file? With -p (patch), Git shows you each changed block and asks whether to stage it:\ngit add -p index.html # Stage this hunk [y,n,q,a,d,s,e,?]? Answer y to stage it, n to leave it out, s to split the block into smaller pieces. That way you can make two clean commits from a single file.\nA convention for messages\nMany teams follow Conventional Commits: a prefix tells the type of change.\nfeat: add the contact form fix: correct the cart total docs: expand the README And if you spot a mistake in your last commit, not pushed yet: git commit --amend lets you fix its message or add a forgotten file.\nExercise · Fix the last commit\nYou just committed, but forgot to add style.css. The commit isn\u0026rsquo;t pushed yet. Add the file to that same commit, without creating a new one.\nShow the solution git add style.css git commit --amend --no-edit --no-edit keeps the current message. Only use --amend on a commit that\u0026rsquo;s not pushed yet: it replaces the commit with a new one, which would cause trouble for anyone who already fetched the old one.\nWhat\u0026rsquo;s Next In the next chapter, we zoom out: how to organize a project\u0026rsquo;s branches with branching strategies.\nThis is Chapter 6 of the Git in Practice course. Follow along to learn how to use Git every day and as a team.\n","permalink":"https://naimidevslayer.com/en/cours/outils/git/git-en-pratique/06-commit-parfait/","summary":"\u003cp\u003eWhat should you do \u003cstrong\u003ebefore\u003c/strong\u003e committing? Here\u0026rsquo;s a simple method for clean commits your teammates will understand right away.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/si7hanw6qRY?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eReview your changes before committing\u003c/li\u003e\n\u003cli\u003eMake commits that cover a single topic\u003c/li\u003e\n\u003cli\u003eWrite a clear commit message\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"1-list-the-changed-files\"\u003e1. List the changed files\u003c/h2\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" class=\"chroma\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003egit status\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eCheck that no file was changed \u003cstrong\u003eby mistake\u003c/strong\u003e. If a file has nothing to do with this commit, don\u0026rsquo;t add it.\u003c/p\u003e","title":"Git in Practice #6: The Perfect Commit"},{"content":"Time for advanced SQL with a super useful concept: subqueries.\nWhat you\u0026#39;ll learn\nWhat a subquery is, and where you can use one Add a computed column, replace a table, filter with IN Copy, update or delete rows based on a result Work around MySQL error 1093 What\u0026rsquo;s a subquery? A subquery is a SQL query nested inside another query, between parentheses. You can use it in SELECT, FROM, WHERE, HAVING, and even in INSERT, UPDATE or DELETE.\nIn SELECT: add a computed column SELECT id, nom, (SELECT COUNT(*) FROM commande WHERE commande.client_id = client.id) AS nb_commandes FROM client; The main query lists the customers (client). The subquery counts the orders (commande) of each customer and adds them as a new column.\nIn FROM: replace a table SELECT AVG(montant) AS montant_moyen FROM ( SELECT montant FROM commande WHERE date_commande \u0026gt;= \u0026#39;2023-01-01\u0026#39; ) AS commandes_recentes; The subquery\u0026rsquo;s result acts as a temporary table, here the amounts (montant) of recent orders. In MySQL, a subquery in FROM must have an alias (here commandes_recentes).\nIn WHERE: compare with a result SELECT nom, prix FROM produit WHERE prix \u0026gt; (SELECT AVG(prix) FROM produit); We compare each product\u0026rsquo;s price (prix) with the average of all products, computed by the subquery.\nIn INSERT: copy a result into a table For example, to copy every customer living in Madrid into a separate table:\nCREATE TABLE client_madrid ( id INT PRIMARY KEY, nom VARCHAR(100) ); INSERT INTO client_madrid (id, nom) SELECT id, nom FROM client WHERE ville = \u0026#39;Madrid\u0026#39;; In UPDATE or DELETE -- Delete posts with fewer likes than average DELETE FROM post WHERE nb_like \u0026lt; (SELECT AVG(nb_like) FROM (SELECT nb_like FROM post) AS p); -- Empty those posts\u0026#39; content instead of deleting them UPDATE post SET content = \u0026#39;\u0026#39; WHERE nb_like \u0026lt; (SELECT AVG(nb_like) FROM (SELECT nb_like FROM post) AS p); The MySQL trap (error 1093): MySQL won\u0026rsquo;t let you modify a table while reading it directly in a subquery (\u0026ldquo;You can\u0026rsquo;t specify target table \u0026lsquo;post\u0026rsquo; for update in FROM clause\u0026rdquo;). The trick: go through a derived table, (SELECT nb_like FROM post) AS p, as above.\nHands-on Back to the tuto_sql database, with its user and post tables.\nUser 1, with the average likes of their posts:\nSELECT *, (SELECT ROUND(AVG(nb_like)) FROM post WHERE user_id = 1) AS nb_like FROM user WHERE id = 1; -- … nb_like: 583 Without the AS nb_like alias, the column would be named after the whole subquery.\nUsers with at least one post above the average likes:\nSELECT * FROM user WHERE id IN ( SELECT DISTINCT user_id FROM post WHERE nb_like \u0026gt; (SELECT AVG(nb_like) FROM post) ); -- 92 rows IN checks whether the id is in the list returned by the subquery. DISTINCT avoids duplicates when a user has several posts above average. The innermost subquery computes the average likes of all posts. Getting an \u0026ldquo;unknown column\u0026rdquo; error? Check the exact column names: here it\u0026rsquo;s user_id, not id_user.\nIN or EXISTS?\nFor \u0026ldquo;users who have at least one post\u0026rdquo;, you can also write:\nSELECT * FROM user u WHERE EXISTS (SELECT 1 FROM post p WHERE p.user_id = u.id); EXISTS only checks whether at least one row exists: it stops as soon as it finds one. Here, the subquery depends on the current row (u.id): it\u0026rsquo;s a correlated subquery.\nAbove all, NOT EXISTS is safer than NOT IN whenever a column may contain NULL: you\u0026rsquo;ll see why in the exercises chapter.\nExercise · Above their own average\nShow the posts that have more likes than their author\u0026rsquo;s average (not the overall average).\nShow the solution SELECT p.id, p.title, p.user_id, p.nb_like FROM post p WHERE p.nb_like \u0026gt; ( SELECT AVG(p2.nb_like) FROM post p2 WHERE p2.user_id = p.user_id ); It\u0026rsquo;s a correlated subquery: for each post p, it recomputes the average of the same user\u0026rsquo;s posts. The p and p2 aliases are essential to tell apart the two uses of the same table.\nWhat\u0026rsquo;s Next In the next chapter, we discover joins. You\u0026rsquo;ll see that some of these queries even become simpler to write.\nThis is Chapter 6 of the SQL from Zero to Pro course. Follow along to learn SQL with MySQL, from the basics to joins.\n","permalink":"https://naimidevslayer.com/en/cours/bases-de-donnees/mysql/sql-de-zero-a-pro/06-sous-requetes/","summary":"\u003cp\u003eTime for advanced SQL with a super useful concept: \u003cstrong\u003esubqueries\u003c/strong\u003e.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/XBjkfScm83M?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eWhat a subquery is, and where you can use one\u003c/li\u003e\n\u003cli\u003eAdd a computed column, replace a table, filter with \u003ccode\u003eIN\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003eCopy, update or delete rows based on a result\u003c/li\u003e\n\u003cli\u003eWork around MySQL error 1093\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"whats-a-subquery\"\u003eWhat\u0026rsquo;s a subquery?\u003c/h2\u003e\n\u003cp\u003eA \u003cstrong\u003esubquery\u003c/strong\u003e is a SQL query \u003cstrong\u003enested inside another query\u003c/strong\u003e, between parentheses. You can use it in \u003ccode\u003eSELECT\u003c/code\u003e, \u003ccode\u003eFROM\u003c/code\u003e, \u003ccode\u003eWHERE\u003c/code\u003e, \u003ccode\u003eHAVING\u003c/code\u003e, and even in \u003ccode\u003eINSERT\u003c/code\u003e, \u003ccode\u003eUPDATE\u003c/code\u003e or \u003ccode\u003eDELETE\u003c/code\u003e.\u003c/p\u003e","title":"SQL from Zero to Pro #6: Subqueries (Nested Queries)"},{"content":"EasyAdmin is installed, but /admin still shows the default welcome page. Before building our first CRUD, let\u0026rsquo;s display our own dashboard, using EasyAdmin\u0026rsquo;s layout so we keep the side menu.\nWhat you\u0026#39;ll learn\nThe three ways to choose what /admin displays Render your own template while keeping EasyAdmin\u0026rsquo;s layout Pass data (statistics) to your dashboard The Three Options in index() Open src/Controller/Admin/DashboardController.php. The generated index() method suggests three options:\nRedirect to an existing page of the back office Redirect conditionally, for example depending on the logged-in user Render your own template, to build a real dashboard with widgets We pick option 3. It\u0026rsquo;s simple, and it gives us full control.\nRendering Our Template Uncomment the render() line and point it to a template in an admin/ folder:\npublic function index(): Response { // Option 3. Render a custom template return $this-\u0026gt;render(\u0026#39;admin/dashboard.html.twig\u0026#39;); } Creating the Template Create the folder templates/admin/ and the file dashboard.html.twig. The template extends EasyAdmin\u0026rsquo;s content page and fills the content block:\n{% extends \u0026#39;@EasyAdmin/page/content.html.twig\u0026#39; %} {% block content %} \u0026lt;h1\u0026gt;Dashboard\u0026lt;/h1\u0026gt; {% endblock %} Extending @EasyAdmin/page/content.html.twig is the key: we get the whole EasyAdmin layout (header, side menu, styles) and only write the content.\nResult Refresh /admin: our dashboard is displayed, with the side menu and its Dashboard item. The icon next to it comes from the menu item we saw in the previous chapter:\nyield MenuItem::linkToDashboard(\u0026#39;Dashboard\u0026#39;, \u0026#39;fa fa-home\u0026#39;); Going further: a real dashboard A dashboard that just says \u0026ldquo;Dashboard\u0026rdquo; is a bit empty. Since index() is a regular Symfony controller, you can inject repositories and pass numbers to the template:\nuse App\\Repository\\AuthorRepository; use App\\Repository\\BookRepository; public function __construct( private readonly BookRepository $bookRepository, private readonly AuthorRepository $authorRepository, ) {} public function index(): Response { return $this-\u0026gt;render(\u0026#39;admin/dashboard.html.twig\u0026#39;, [ \u0026#39;nbBooks\u0026#39; =\u0026gt; $this-\u0026gt;bookRepository-\u0026gt;count([]), \u0026#39;nbAuthors\u0026#39; =\u0026gt; $this-\u0026gt;authorRepository-\u0026gt;count([]), ]); } {% extends \u0026#39;@EasyAdmin/page/content.html.twig\u0026#39; %} {% block content %} \u0026lt;h1\u0026gt;Mini Library\u0026lt;/h1\u0026gt; \u0026lt;p\u0026gt;{{ nbBooks }} books · {{ nbAuthors }} authors\u0026lt;/p\u0026gt; {% endblock %} count([]) counts every row in the table, with no filter.\nRecap index() decides what /admin displays $this-\u0026gt;render('admin/dashboard.html.twig') renders our own page Extending @EasyAdmin/page/content.html.twig keeps the EasyAdmin layout Exercise · The number of categories\nAdd the number of categories to the dashboard, the same way as books and authors.\nShow the solution Inject CategoryRepository in the constructor, then:\n\u0026#39;nbCategories\u0026#39; =\u0026gt; $this-\u0026gt;categoryRepository-\u0026gt;count([]), And in the template:\n\u0026lt;p\u0026gt;{{ nbBooks }} books · {{ nbAuthors }} authors · {{ nbCategories }} categories\u0026lt;/p\u0026gt; What\u0026rsquo;s Next We\u0026rsquo;ll create our first CRUD, for categories, and customize its labels.\nThis is Chapter 6 of the Mini Library course. Follow along to build a complete Symfony 8 + EasyAdmin digital library application from scratch.\n","permalink":"https://naimidevslayer.com/en/cours/developpement-web/symfony-8/mini-bibliotheque/06-easyadmin-dashboard/","summary":"\u003cp\u003eEasyAdmin is installed, but \u003ccode\u003e/admin\u003c/code\u003e still shows the default welcome page. Before building our first CRUD, let\u0026rsquo;s display \u003cstrong\u003eour own dashboard\u003c/strong\u003e, using EasyAdmin\u0026rsquo;s layout so we keep the side menu.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/wTXEL10rPps?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eThe three ways to choose what \u003ccode\u003e/admin\u003c/code\u003e displays\u003c/li\u003e\n\u003cli\u003eRender your own template while keeping EasyAdmin\u0026rsquo;s layout\u003c/li\u003e\n\u003cli\u003ePass data (statistics) to your dashboard\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"the-three-options-in-index\"\u003eThe Three Options in \u003ccode\u003eindex()\u003c/code\u003e\u003c/h2\u003e\n\u003cp\u003eOpen \u003ccode\u003esrc/Controller/Admin/DashboardController.php\u003c/code\u003e. The generated \u003ccode\u003eindex()\u003c/code\u003e method suggests three options:\u003c/p\u003e","title":"Mini Library Course #6: Display Your Own EasyAdmin Dashboard"},{"content":"A very important topic when working as a team: branching strategies.\nWhat you\u0026#39;ll learn\nThe difference between long-running and short-lived branches GitHub Flow: a single main branch Git Flow: main, develop, feature, release and hotfix Build your own workflow Git leaves you free… and that\u0026rsquo;s the problem Git gives you every tool to manage branches, but it doesn\u0026rsquo;t impose any way of doing things. It\u0026rsquo;s up to you and your team to use them well.\nStep one: write a convention approved by the whole team, describing the project\u0026rsquo;s Git best practices. It prevents mistakes, whether for a long-time member or a new developer.\nTwo kinds of branches Long-running branches Every project has at least one: main (or master). They live for the whole life of the project. You never commit directly to them: changes arrive through a merge or a rebase. Short-lived branches They\u0026rsquo;re created for a specific goal: a feature, a fix… They always start from a long-running branch, never from another short-lived one. Once validated and merged, you delete them. GitHub Flow: the simplest One long-running branch: main. Every other branch is short-lived. Every change, fix or addition starts from main and goes back into main. main feature/a fix/b merge merge GitHub Flow: every branch starts from main and comes back to it through a pull request. Great for small teams and projects deployed continuously.\nGit Flow: more structured More rules, but more control. Two long-running branches:\nmain (or master): the official history of production releases; develop: the integration branch for features. And short-lived branches, each with its own role:\nBranch Starts from Goes back into Role feature/* develop develop A new feature release/* develop main and develop Prepare a production release with the new commits from develop hotfix/* main main and develop An urgent production fix The hotfix is the only case where a short-lived branch touches main directly, because it\u0026rsquo;s a production emergency. Don\u0026rsquo;t forget to bring the fix into develop before deleting the branch, or the bug will come back with the next release.\nmain hotfix/* release/* develop feature/* v1.0 v1.0.1 prod emergency Git Flow: features go through develop, versions through release, and emergencies through hotfix. What if neither fits? Nothing forces you to follow one of these models. You can build your own workflow, based on your team\u0026rsquo;s size and needs.\nExample: a development team and a test team work on the same project. You could have three long-running branches:\nmain: production; recette (or test): for the testers\u0026rsquo; acceptance testing; develop: for the dev team to validate developments. Short-lived branches still follow the same principle.\nExercise · Which strategy?\nFor each project, which strategy would you pick?\nYour personal blog, deployed as soon as a post is ready. A mobile app released on the stores every 6 weeks, with a team of 8 developers. Show the solution GitHub Flow. One person, continuous deployment: a main branch that\u0026rsquo;s always live plus short-lived branches is plenty. Git Flow would add steps for nothing. Git Flow. Releases are planned: develop collects features, a release branch stabilizes the version before publishing, and hotfix fixes a production bug without shipping work in progress. What\u0026rsquo;s Next In the next chapter, we see concretely how a developer proposes changes with pull requests and forks.\nThis is Chapter 7 of the Git in Practice course. Follow along to learn how to use Git every day and as a team.\n","permalink":"https://naimidevslayer.com/en/cours/outils/git/git-en-pratique/07-strategies-branches/","summary":"\u003cp\u003eA very important topic when working as a team: \u003cstrong\u003ebranching strategies\u003c/strong\u003e.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/usTOnmepUJQ?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eThe difference between long-running and short-lived branches\u003c/li\u003e\n\u003cli\u003eGitHub Flow: a single \u003ccode\u003emain\u003c/code\u003e branch\u003c/li\u003e\n\u003cli\u003eGit Flow: \u003ccode\u003emain\u003c/code\u003e, \u003ccode\u003edevelop\u003c/code\u003e, \u003ccode\u003efeature\u003c/code\u003e, \u003ccode\u003erelease\u003c/code\u003e and \u003ccode\u003ehotfix\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003eBuild your own workflow\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"git-leaves-you-free-and-thats-the-problem\"\u003eGit leaves you free… and that\u0026rsquo;s the problem\u003c/h2\u003e\n\u003cp\u003eGit gives you every tool to manage branches, but it doesn\u0026rsquo;t impose \u003cstrong\u003eany way of doing things\u003c/strong\u003e. It\u0026rsquo;s up to you and your team to use them well.\u003c/p\u003e","title":"Git in Practice #7: Branching Strategies (GitHub Flow, Git Flow)"},{"content":"If you\u0026rsquo;ve ever worked with several tables, you\u0026rsquo;ve surely needed to cross-reference their data. That\u0026rsquo;s exactly what joins do: they link information spread across different tables to get useful results.\nWhat you\u0026#39;ll learn\nVisualize joins before writing them INNER JOIN, LEFT JOIN and RIGHT JOIN, with prefixes and aliases Emulate a FULL OUTER JOIN in MySQL with UNION Replace a subquery with a join Visualizing joins The easiest way to understand joins is a circle diagram (like the ones on sql.sh), before you even write the query. With two tables A and B:\nJoin What you get INNER JOIN Only the intersection: rows present in A and in B LEFT JOIN All of table A, plus the matches in B RIGHT JOIN All of table B, plus the matches in A FULL OUTER JOIN Everything, from both sides A B INNER JOIN A B LEFT JOIN A B RIGHT JOIN A B FULL JOIN The four joins: the colored part is what the query returns. Sample tables A client (customer) table and a commande (order) table:\nCREATE TABLE client ( id INT PRIMARY KEY, nom VARCHAR(100), ville VARCHAR(100) ); CREATE TABLE commande ( id INT PRIMARY KEY, client_id INT, produit VARCHAR(100) ); INSERT INTO client VALUES (1, \u0026#39;Alice\u0026#39;, \u0026#39;Paris\u0026#39;), (2, \u0026#39;Bob\u0026#39;, \u0026#39;Lyon\u0026#39;), (3, \u0026#39;Charlie\u0026#39;, \u0026#39;Nice\u0026#39;); INSERT INTO commande VALUES (1, 1, \u0026#39;Ordinateur\u0026#39;), (2, 2, \u0026#39;Téléphone\u0026#39;), (3, 4, \u0026#39;Tablette\u0026#39;); Alice and Bob have an order, Charlie has none. The \u0026ldquo;Tablette\u0026rdquo; order has a client_id of 4, a customer who doesn\u0026rsquo;t exist in the client table. INNER JOIN: the intersection SELECT client.nom, commande.produit FROM client INNER JOIN commande ON client.id = commande.client_id; nom produit Alice Ordinateur Bob Téléphone We only get customers who placed an order. Charlie and the tablet don\u0026rsquo;t appear.\nPrefixes and aliases We write client.id and commande.client_id so SQL knows which table each column comes from. It\u0026rsquo;s essential when both tables have a column with the same name. To keep it short, give each table an alias:\nSELECT c.nom, co.produit FROM client c INNER JOIN commande co ON c.id = co.client_id; LEFT JOIN: the whole left table SELECT c.nom, co.produit FROM client c LEFT JOIN commande co ON c.id = co.client_id; nom produit Alice Ordinateur Bob Téléphone Charlie NULL Every customer is there. Charlie, who has no order, gets NULL columns on the commande side.\nRIGHT JOIN: the whole right table SELECT c.nom, co.produit FROM client c RIGHT JOIN commande co ON c.id = co.client_id; nom produit Alice Ordinateur Bob Téléphone NULL Tablette Every order is there. The tablet, whose customer doesn\u0026rsquo;t exist, gets a NULL name.\nA RIGHT JOIN is just a flipped LEFT JOIN. The same query can be written FROM commande co LEFT JOIN client c ON ….\nFULL OUTER JOIN: everything SELECT c.nom, co.produit FROM client c FULL OUTER JOIN commande co ON c.id = co.client_id; nom produit Alice Ordinateur Bob Téléphone Charlie NULL NULL Tablette FULL OUTER JOIN exists in PostgreSQL, SQL Server and Oracle, but not in MySQL.\nThe MySQL solution In the video, I left this as a question. Here\u0026rsquo;s the answer: combine a LEFT JOIN and a RIGHT JOIN with UNION, which merges both results and removes duplicates:\nSELECT c.nom, co.produit FROM client c LEFT JOIN commande co ON c.id = co.client_id UNION SELECT c.nom, co.produit FROM client c RIGHT JOIN commande co ON c.id = co.client_id; You get exactly the table above.\nRewriting a subquery with a join In the previous chapter, we showed user 1 with the average likes of their posts using a subquery. With a join:\nSELECT u.*, ROUND(AVG(p.nb_like)) AS nb_like FROM user u LEFT JOIN post p ON u.id = p.user_id WHERE u.id = 1 GROUP BY u.id; Two important points:\nu.*, not *. With a join, * returns the columns of both tables. u.* keeps only those of user. GROUP BY u.id. We\u0026rsquo;re mixing columns with an aggregate function: MySQL (in ONLY_FULL_GROUP_BY mode, on by default) then requires a grouping. Since id is the primary key, MySQL knows the other user columns depend on it. With MariaDB, list every column: GROUP BY u.id, u.name, u.birthday, u.city. The result is the same as the subquery version, but the query is easier to read.\nThe LEFT JOIN that turns back into an INNER JOIN\nWe want every customer, with their paid orders if they have any. First idea:\nSELECT c.nom, co.statut FROM client c LEFT JOIN commande co ON co.client_id = c.id WHERE co.statut = \u0026#39;payee\u0026#39;; Wrong: customers without a paid order disappear. For them, co.statut is NULL, and the WHERE drops them. The LEFT JOIN then behaves like an INNER JOIN.\nThe fix: put the condition on the right-hand table inside the ON:\nSELECT c.nom, co.statut FROM client c LEFT JOIN commande co ON co.client_id = c.id AND co.statut = \u0026#39;payee\u0026#39;; Every customer is there, with NULL when they have no paid order. You\u0026rsquo;ll meet this trap again in the Employee Bonus exercise of chapter 9.\nExercise · Customers without orders\nUsing the chapter\u0026rsquo;s client and commande tables, show the customers who have no order, with a join.\nShow the solution SELECT c.nom FROM client c LEFT JOIN commande co ON co.client_id = c.id WHERE co.id IS NULL; -- Charlie The LEFT JOIN keeps every customer. For those without an order, every commande column is NULL: just filter them with IS NULL. That\u0026rsquo;s the \u0026ldquo;left part only\u0026rdquo; of the diagram.\nWhat\u0026rsquo;s Next That\u0026rsquo;s it for the theory! In the next chapter, we move on to hands-on exercises.\nThis is Chapter 7 of the SQL from Zero to Pro course. Follow along to learn SQL with MySQL, from the basics to joins.\n","permalink":"https://naimidevslayer.com/en/cours/bases-de-donnees/mysql/sql-de-zero-a-pro/07-jointures/","summary":"\u003cp\u003eIf you\u0026rsquo;ve ever worked with several tables, you\u0026rsquo;ve surely needed to cross-reference their data. That\u0026rsquo;s exactly what \u003cstrong\u003ejoins\u003c/strong\u003e do: they link information spread across different tables to get useful results.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/hkwM-npTqKg?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eVisualize joins before writing them\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003eINNER JOIN\u003c/code\u003e, \u003ccode\u003eLEFT JOIN\u003c/code\u003e and \u003ccode\u003eRIGHT JOIN\u003c/code\u003e, with prefixes and aliases\u003c/li\u003e\n\u003cli\u003eEmulate a \u003ccode\u003eFULL OUTER JOIN\u003c/code\u003e in MySQL with \u003ccode\u003eUNION\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003eReplace a subquery with a join\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"visualizing-joins\"\u003eVisualizing joins\u003c/h2\u003e\n\u003cp\u003eThe easiest way to understand joins is a \u003cstrong\u003ecircle diagram\u003c/strong\u003e (like the ones on sql.sh), before you even write the query. With two tables A and B:\u003c/p\u003e","title":"SQL from Zero to Pro #7: Joins (INNER, LEFT, RIGHT, FULL JOIN)"},{"content":"Time for our first CRUD screen: create, list, edit and delete. We start with the simplest entity, Category, which has a single field.\nWhat you\u0026#39;ll learn\nGenerate a CRUD controller with make:admin:crud Choose the displayed fields and their labels Add the CRUD to the dashboard menu Customize page titles and buttons Generating the CRUD Controller symfony console make:admin:crud EasyAdmin detects our three entities and numbers them:\n[0] App\\Entity\\Author [1] App\\Entity\\Book [2] App\\Entity\\Category We choose 2 (Category) and keep the defaults, so the controller goes in the Admin namespace: src/Controller/Admin/CategoryCrudController.php.\nConfiguring the Fields configureFields() decides which fields are displayed. The generated example contains three fields (IdField, TextField, TextEditorField), but Category only has one, a simple string. So we keep a single TextField:\npublic function configureFields(string $pageName): iterable { return [ TextField::new(\u0026#39;categoryName\u0026#39;, \u0026#39;Nom de la catégorie\u0026#39;), ]; } The first argument is the property name in the entity. The second is the label shown in the interface (here in French). TextEditorField would display a rich text editor. That\u0026rsquo;s useful for long content, but too much for a category name.\nAdding It to the Menu Back in DashboardController, add a menu item that points to our CRUD controller, with a label and an icon:\npublic function configureMenuItems(): iterable { yield MenuItem::linkToDashboard(\u0026#39;Dashboard\u0026#39;, \u0026#39;fa fa-home\u0026#39;); yield MenuItem::linkTo(CategoryCrudController::class, \u0026#39;Catégorie\u0026#39;, \u0026#39;fa fa-tag\u0026#39;); } Refresh: Catégorie appears in the menu. Click it and you get a list of categories, an Add category button, and edit and delete actions. With one command and a couple of lines, we already have a complete management screen.\nCustom Page Titles Override configureCrud() and set a title for each of the four pages: index, new, edit and detail.\npublic function configureCrud(Crud $crud): Crud { return $crud -\u0026gt;setPageTitle(Crud::PAGE_INDEX, \u0026#39;🏷️ Toutes les catégories\u0026#39;) -\u0026gt;setPageTitle(Crud::PAGE_NEW, \u0026#39;➕ Ajouter une catégorie\u0026#39;) -\u0026gt;setPageTitle(Crud::PAGE_EDIT, \u0026#39;✏️ Modifier une catégorie\u0026#39;) -\u0026gt;setPageTitle(Crud::PAGE_DETAIL, \u0026#39;ℹ️ Détails de la catégorie\u0026#39;); } Custom Buttons The buttons are still in English. They aren\u0026rsquo;t fields, they\u0026rsquo;re actions, so we override configureActions(). update() takes the page, the action, and a callback that returns the modified action:\npublic function configureActions(Actions $actions): Actions { return $actions -\u0026gt;update(Crud::PAGE_INDEX, Action::NEW, function (Action $action) { return $action -\u0026gt;setLabel(\u0026#39;Ajouter une catégorie\u0026#39;) -\u0026gt;setIcon(\u0026#39;fa fa-plus\u0026#39;); }); } The New button now reads Ajouter une catégorie, with a plus icon. The other buttons (Create, Create and add another…) work exactly the same way. Try them yourself.\nExplore AbstractCrudController. It lists every method you can override: configureCrud, configureFields, configureActions, configureFilters… Everything you need to tailor the admin to your project.\nYour Turn Before the next chapter, build the Author CRUD yourself, using the same steps. The next chapter shows the final result.\nFaster: the entity labels\nRather than rewriting each page title, you can give EasyAdmin the entity\u0026rsquo;s name, singular and plural. It then uses it everywhere: titles, \u0026ldquo;Add\u0026rdquo; buttons, messages…\npublic function configureCrud(Crud $crud): Crud { return $crud -\u0026gt;setEntityLabelInSingular(\u0026#39;Category\u0026#39;) -\u0026gt;setEntityLabelInPlural(\u0026#39;Categories\u0026#39;); } Keep setPageTitle() for pages where you want a truly different title.\nCommon mistake\n\u0026ldquo;Attempted to load class \u0026ldquo;Action\u0026rdquo;\u0026rdquo; or \u0026ldquo;Class not found\u0026rdquo;? A use statement is missing at the top of the controller. The classes used here all come from EasyAdmin:\nuse EasyCorp\\Bundle\\EasyAdminBundle\\Config\\Action; use EasyCorp\\Bundle\\EasyAdminBundle\\Config\\Actions; use EasyCorp\\Bundle\\EasyAdminBundle\\Config\\Crud; use EasyCorp\\Bundle\\EasyAdminBundle\\Field\\TextField; With VS Code\u0026rsquo;s PHP Intelephense extension, the import is added automatically when you pick the class from autocomplete.\nRecap make:admin:crud generates a CRUD controller for an entity configureFields() → which fields, with which labels MenuItem::linkTo() adds the CRUD to the menu configureCrud() → page titles; configureActions() → buttons Exercise · The save button\nOn the category creation page, rename the \u0026ldquo;Create\u0026rdquo; button to \u0026ldquo;Save\u0026rdquo;.\nShow the solution On the new page, the \u0026ldquo;Create\u0026rdquo; button is the SAVE_AND_RETURN action:\n-\u0026gt;update(Crud::PAGE_NEW, Action::SAVE_AND_RETURN, function (Action $action) { return $action-\u0026gt;setLabel(\u0026#39;Save\u0026#39;); }) The \u0026ldquo;Create and add another\u0026rdquo; button is Action::SAVE_AND_ADD_ANOTHER.\nThis is Chapter 7 of the Mini Library course. Follow along to build a complete Symfony 8 + EasyAdmin digital library application from scratch.\n","permalink":"https://naimidevslayer.com/en/cours/developpement-web/symfony-8/mini-bibliotheque/07-easyadmin-crud-labels/","summary":"\u003cp\u003eTime for our first \u003cstrong\u003eCRUD\u003c/strong\u003e screen: create, list, edit and delete. We start with the simplest entity, \u003cstrong\u003eCategory\u003c/strong\u003e, which has a single field.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/6KsbbFEs2Mk?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eGenerate a CRUD controller with \u003ccode\u003emake:admin:crud\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003eChoose the displayed fields and their labels\u003c/li\u003e\n\u003cli\u003eAdd the CRUD to the dashboard menu\u003c/li\u003e\n\u003cli\u003eCustomize page titles and buttons\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"generating-the-crud-controller\"\u003eGenerating the CRUD Controller\u003c/h2\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" class=\"chroma\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003esymfony console make:admin:crud\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eEasyAdmin detects our three entities and numbers them:\u003c/p\u003e","title":"Mini Library Course #7: Create an EasyAdmin CRUD \u0026 Customize Its Labels"},{"content":"In the previous chapter, we covered branching strategies. Here, we get concrete, from the developer\u0026rsquo;s side, based on Git Flow.\nWhat you\u0026#39;ll learn\nWhat a pull request is, and what a fork is Contribute to a project you don\u0026rsquo;t own How a code review works Pick the right merge option The problem I created my branch from develop, finished my work and pushed it. Now what?\nThe logical next step would be to merge my branch into develop. But if there\u0026rsquo;s no code review first, two steps are missing:\nLet the team know my task is done and needs a code review before being merged. The lead must check the commits before integrating them. To handle both steps simply, we use pull requests.\nWhat\u0026rsquo;s a pull request? A pull request (PR) is an integration request: it lets a developer notify the team that a feature is done, and propose the changes so they can be reviewed before being merged.\nWhat\u0026rsquo;s a fork? To better protect the project, we add forks. A fork is a copy of the project in your own account. You can make any change you like there without touching the original project. To propose your changes, you open a pull request: the lead reviews the code, then accepts or rejects it.\nExample on GitHub 1. Fork the project On the project page, click Fork. GitHub creates the copy in your account: your-account/the-project, marked forked from the original project.\n2. Clone the fork From the command line with git clone, or with GitHub Desktop, simpler if you\u0026rsquo;re starting out.\n3. Create a branch and make your changes git branch # * master git checkout -b feature/1 # … changes … git status git commit -am \u0026#34;Change 1\u0026#34; git push -u origin feature/1 In GitHub Desktop, the Publish branch button does the same as that last git push.\n4. Open the pull request On GitHub, go to the Pull requests tab, then New pull request. GitHub shows two sides:\nbase: the original project and the branch you want to merge into (here master); compare: your fork and your branch (here feature/1). GitHub shows all your changes one last time. Forgot something? Make a new commit and push it: it\u0026rsquo;s automatically added to the same pull request.\nClick Create pull request.\n5. Code review On the original project, the pull request shows up. The lead:\nchecks the commits; goes through the changes in the Files changed tab: that\u0026rsquo;s the code review; then accepts (merges) or rejects. Merge options Option What it does Create a merge commit Keeps every commit and adds a merge commit Squash and merge Combines all the PR\u0026rsquo;s commits into one, ideal when there are several Rebase and merge Replays the commits one by one onto the target branch, with no merge commit Once the PR is merged, your changes are on the original project\u0026rsquo;s master branch.\nA pull request that gets merged fast\nSmall: a PR touching 50 lines gets reviewed within the hour, a 2,000-line PR waits for days. One topic, just like a good commit. A description: what changes, why, and how to test it. A screenshot helps a lot for a visual change. A draft pull request lets you show unfinished work and get feedback early. Exercise · Which merge option?\nYour PR has 6 commits: \u0026ldquo;wip\u0026rdquo;, \u0026ldquo;fix typo\u0026rdquo;, \u0026ldquo;another fix\u0026rdquo;, \u0026ldquo;add the form\u0026rdquo;… Which merge option keeps a clean history on main?\nShow the solution Squash and merge. The 6 commits become a single commit on main, with a clear message like \u0026ldquo;Add the contact form\u0026rdquo;. The intermediate steps don\u0026rsquo;t clutter the project\u0026rsquo;s history.\nWhat\u0026rsquo;s Next Your fork is a copy: how do you get the original project\u0026rsquo;s new changes? The answer comes in the next chapter, with the upstream remote.\nThis is Chapter 8 of the Git in Practice course. Follow along to learn how to use Git every day and as a team.\n","permalink":"https://naimidevslayer.com/en/cours/outils/git/git-en-pratique/08-pull-request-fork/","summary":"\u003cp\u003eIn the previous chapter, we covered branching strategies. Here, we get concrete, from the developer\u0026rsquo;s side, based on Git Flow.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/91q88rYyxo0?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eWhat a pull request is, and what a fork is\u003c/li\u003e\n\u003cli\u003eContribute to a project you don\u0026rsquo;t own\u003c/li\u003e\n\u003cli\u003eHow a code review works\u003c/li\u003e\n\u003cli\u003ePick the right merge option\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"the-problem\"\u003eThe problem\u003c/h2\u003e\n\u003cp\u003eI created my branch from \u003ccode\u003edevelop\u003c/code\u003e, finished my work and pushed it. Now what?\u003c/p\u003e","title":"Git in Practice #8: Pull Requests and Forks on GitHub"},{"content":"Time to practice! We solve SQL problems on LeetCode, one of the best platforms to train and prepare for technical interviews. It offers problems in algorithms, databases, shell, concurrency and JavaScript. Here, we pick the Database category, Easy level.\nWhat you\u0026#39;ll learn\nSolve 5 \u0026ldquo;Easy\u0026rdquo; SQL problems from LeetCode Choose between a join and a subquery Join a table with itself (self-join) Match the expected output format exactly LeetCode tip: Run tests your query on the example, Submit checks it against every test case and shows its performance. If you\u0026rsquo;re stuck, the Solutions tab shows how others solved the problem.\n1. Combine Two Tables Tables:\nPerson: personId (primary key), lastName, firstName Address: addressId (primary key), personId (foreign key), city, state Task: show firstName, lastName, city and state for every person. If a person has no address, city and state are NULL.\nReasoning: the reference table is Person, and we want every person, even without an address: that\u0026rsquo;s a LEFT JOIN.\nSELECT p.firstName, p.lastName, a.city, a.state FROM Person p LEFT JOIN Address a ON a.personId = p.personId; 2. Duplicate Emails Table: Person: id (primary key), email\nTask: show the emails that appear more than once.\nReasoning: group by email with GROUP BY, then keep groups with more than one row using HAVING COUNT(*) \u0026gt; 1.\nSELECT email AS Email FROM Person GROUP BY email HAVING COUNT(*) \u0026gt; 1; GROUP BY gathers all rows with the same email. HAVING then checks, for each group, how many rows it contains.\n3. Delete Duplicate Emails Task: delete duplicate emails, keeping for each one only the row with the smallest id.\nReasoning: GROUP BY … HAVING isn\u0026rsquo;t enough here, since it would delete every row in the group. Instead, we join the table with itself to compare rows pairwise:\nDELETE p1 FROM Person p1 JOIN Person p2 ON p1.email = p2.email WHERE p1.id \u0026gt; p2.id; p1.email = p2.email: find pairs of rows with the same email. p1.id \u0026gt; p2.id: delete the one with the larger id, so the oldest one stays. Example: with john@example.com at id 1 and 3, only row 3 is deleted.\n4. Customers Who Never Order Tables:\nCustomers: id, name Orders: id, customerId (foreign key to Customers) Task: show the customers who never placed an order, in a column named Customers.\nReasoning: no join needed here, a subquery with NOT IN does the job: we exclude every customer found in Orders.\nSELECT name AS Customers FROM Customers WHERE id NOT IN (SELECT customerId FROM Orders); Watch the expected column name: without AS Customers, the answer is rejected even if the data is right.\nNOT IN and NULL: the classic trap\nThis solution works on LeetCode because customerId is never empty. But if a single order had a NULL customerId, the query would return… no customers at all. NOT IN compares each id with every value in the list, and a comparison with NULL is never true.\nTwo safe versions that work in every case:\n-- With NOT EXISTS SELECT name AS Customers FROM Customers c WHERE NOT EXISTS (SELECT 1 FROM Orders o WHERE o.customerId = c.id); -- With a join SELECT c.name AS Customers FROM Customers c LEFT JOIN Orders o ON o.customerId = c.id WHERE o.id IS NULL; 5. Employees Earning More Than Their Managers Table: Employee: id, name, salary, managerId\nTask: show, in an Employee column, the employees who earn more than their manager.\nExample: Joe earns 70,000 and his manager Sam 60,000, so Joe is in the result. Henry earns 80,000 and his manager Max 90,000, so Henry isn\u0026rsquo;t.\nSolution with a subquery: for each employee e1, fetch the salary of their manager e2:\nSELECT e1.name AS Employee FROM Employee e1 WHERE e1.salary \u0026gt; ( SELECT e2.salary FROM Employee e2 WHERE e2.id = e1.managerId ); Solution with a join, often faster: join the table with itself, one side for the employee, the other for their manager:\nSELECT e1.name AS Employee FROM Employee e1 JOIN Employee e2 ON e1.managerId = e2.id WHERE e1.salary \u0026gt; e2.salary; After a Submit, LeetCode shows your query\u0026rsquo;s performance. A query can be correct but slow: comparing it with other solutions is a great way to improve.\nMy method for an SQL exercise\nRead the expected output before the instructions: column names, order, duplicates. Spot the tables you need, and how they\u0026rsquo;re linked. Write the query step by step: first the FROM and joins, then the WHERE, then the SELECT. Think about edge cases: NULL, duplicates, empty tables. What\u0026rsquo;s Next Five easy problems solved! Part two comes in the next chapter.\nThis is Chapter 8 of the SQL from Zero to Pro course. Follow along to learn SQL with MySQL, from the basics to joins.\n","permalink":"https://naimidevslayer.com/en/cours/bases-de-donnees/mysql/sql-de-zero-a-pro/08-exercices-partie-1/","summary":"\u003cp\u003eTime to practice! We solve SQL problems on \u003cstrong\u003eLeetCode\u003c/strong\u003e, one of the best platforms to train and prepare for technical interviews. It offers problems in algorithms, databases, shell, concurrency and JavaScript. Here, we pick the \u003cstrong\u003eDatabase\u003c/strong\u003e category, \u003cstrong\u003eEasy\u003c/strong\u003e level.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/XqKi8moeMSg?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e","title":"SQL from Zero to Pro #8: Hands-On LeetCode Exercises (Part 1)"},{"content":"Last time, I left you the Author CRUD as an exercise. Here\u0026rsquo;s my version, a quick test, and then the simplest way to translate the whole admin into French.\nWhat you\u0026#39;ll learn\nBuild the Author CRUD with slug, rich text and date fields Display rich text correctly in the detail view Translate the whole admin into French with one line Push the work to GitHub The Author CRUD The Author entry is in the menu, and the whole screen is in French: Tous les auteurs, Ajouter un auteur, and every button.\nThe menu item public function configureMenuItems(): iterable { yield MenuItem::linkToDashboard(\u0026#39;Dashboard\u0026#39;, \u0026#39;fa fa-home\u0026#39;); yield MenuItem::linkTo(AuthorCrudController::class, \u0026#39;Auteur\u0026#39;, \u0026#39;fa fa-user\u0026#39;); yield MenuItem::linkTo(CategoryCrudController::class, \u0026#39;Catégorie\u0026#39;, \u0026#39;fa fa-tag\u0026#39;); } The fields public function configureFields(string $pageName): iterable { return [ TextField::new(\u0026#39;firstName\u0026#39;)-\u0026gt;setLabel(\u0026#39;Prénom\u0026#39;), TextField::new(\u0026#39;lastName\u0026#39;)-\u0026gt;setLabel(\u0026#39;Nom\u0026#39;)-\u0026gt;setRequired(true)-\u0026gt;setSortable(true), SlugField::new(\u0026#39;authorSlug\u0026#39;)-\u0026gt;setTargetFieldName([\u0026#39;firstName\u0026#39;, \u0026#39;lastName\u0026#39;])-\u0026gt;setLabel(\u0026#39;Slug\u0026#39;), TextEditorField::new(\u0026#39;biography\u0026#39;)-\u0026gt;setLabel(\u0026#39;Biographie\u0026#39;) -\u0026gt;formatValue(fn (?string $value) =\u0026gt; new Markup($value ?? \u0026#39;\u0026#39;, \u0026#39;UTF-8\u0026#39;)), DateField::new(\u0026#39;birthday\u0026#39;)-\u0026gt;setLabel(\u0026#39;Date de naissance\u0026#39;)-\u0026gt;setFormat(\u0026#39;dd-MM-yyyy\u0026#39;), ]; } Field Type Why First and last name TextField Simple text Slug SlugField Built from first and last name, used in URLs Biography TextEditorField Rich text: bold, italic, links, lists… Date of birth DateField With a French date format Wrapping the biography in a Twig Markup object renders the formatting (bold, italic) in the detail view, instead of raw HTML.\nAn empty biography crashes the page\nThe biography column is nullable: an author may have no biography. With fn (string $value), PHP throws a TypeError as soon as it receives null. Hence the ?string and the $value ?? '' in the code above: this small detail avoids an error page on the first author without a biography.\nWatch out\nMarkup outputs the HTML as is. It\u0026rsquo;s safe here, since only administrators write biographies. But never use this technique to display content typed by visitors: a malicious \u0026lt;script\u0026gt; would run (an XSS vulnerability).\nThe actions Same principle as the Category CRUD, with more buttons customized: new, edit, delete, view, create… We also add the detail action to the list, since it isn\u0026rsquo;t enabled by default:\npublic function configureActions(Actions $actions): Actions { return $actions -\u0026gt;add(Crud::PAGE_INDEX, Action::DETAIL) -\u0026gt;update(Crud::PAGE_INDEX, Action::NEW, fn (Action $a) =\u0026gt; $a-\u0026gt;setLabel(\u0026#39;Ajouter un auteur\u0026#39;)) -\u0026gt;update(Crud::PAGE_INDEX, Action::EDIT, fn (Action $a) =\u0026gt; $a-\u0026gt;setLabel(\u0026#39;Éditer\u0026#39;)) -\u0026gt;update(Crud::PAGE_INDEX, Action::DELETE, fn (Action $a) =\u0026gt; $a-\u0026gt;setLabel(\u0026#39;Retirer\u0026#39;)) -\u0026gt;update(Crud::PAGE_INDEX, Action::DETAIL, fn (Action $a) =\u0026gt; $a-\u0026gt;setLabel(\u0026#39;Voir\u0026#39;)); } I did the same for the Category buttons.\nA quick test Create an author named Test, with a biography in bold and italic, and click Create. It shows up at the end of the list, and the detail view displays the formatting correctly. Then delete it, and it\u0026rsquo;s gone.\nTranslating the Rest of EasyAdmin Some texts are still in English: the delete confirmation pop-up, the search field, \u0026ldquo;20 results\u0026rdquo;… You have three options:\nBy hand, in each CRUD controller, as we did for the labels and buttons. Precise, but long. With Symfony\u0026rsquo;s translation files, instead of writing every label in the code. Change the default locale. EasyAdmin then uses its own built-in French translations everywhere. Option 3 is the quickest. Open config/packages/translation.yaml and change en to fr:\nframework: default_locale: fr translator: default_path: \u0026#39;%kernel.project_dir%/translations\u0026#39; Refresh: Search becomes Rechercher, the result count is in French, and so is the delete confirmation. This works with any language you need.\nPushing to GitHub As usual, we save our work:\ngit status git add . git commit -m \u0026#34;author category crud\u0026#34; git push origin main On GitHub, the minibib repository now contains the changes.\nCustom translations\nWith the fr locale, EasyAdmin translates its own texts. For your own texts (labels, titles), Symfony offers translation files: write keys in the code, and their values in translations/messages.fr.yaml.\n# translations/messages.fr.yaml author.first_name: Prénom author.last_name: Nom TextField::new(\u0026#39;firstName\u0026#39;)-\u0026gt;setLabel(\u0026#39;author.first_name\u0026#39;), It\u0026rsquo;s the best option if the admin is one day needed in several languages.\nExercise · A filter by name\nAdd a filter on the last name to the Author CRUD, to quickly find an author in a long list.\nShow the solution use EasyCorp\\Bundle\\EasyAdminBundle\\Config\\Filters; public function configureFilters(Filters $filters): Filters { return $filters-\u0026gt;add(\u0026#39;lastName\u0026#39;); } A Filters button appears above the list. EasyAdmin picks the right kind of filter based on the field\u0026rsquo;s type.\nWhat\u0026rsquo;s Next Next up is the most important entity of the project: the Book CRUD.\nThis is Chapter 8 of the Mini Library course. Follow along to build a complete Symfony 8 + EasyAdmin digital library application from scratch.\n","permalink":"https://naimidevslayer.com/en/cours/developpement-web/symfony-8/mini-bibliotheque/08-author-crud-translations/","summary":"\u003cp\u003eLast time, I left you the \u003cstrong\u003eAuthor\u003c/strong\u003e CRUD as an exercise. Here\u0026rsquo;s my version, a quick test, and then the simplest way to \u003cstrong\u003etranslate the whole admin into French\u003c/strong\u003e.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/CODVynwCInY?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eBuild the Author CRUD with slug, rich text and date fields\u003c/li\u003e\n\u003cli\u003eDisplay rich text correctly in the detail view\u003c/li\u003e\n\u003cli\u003eTranslate the whole admin into French with one line\u003c/li\u003e\n\u003cli\u003ePush the work to GitHub\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"the-author-crud\"\u003eThe Author CRUD\u003c/h2\u003e\n\u003cp\u003eThe Author entry is in the menu, and the whole screen is in French: \u003cem\u003eTous les auteurs\u003c/em\u003e, \u003cem\u003eAjouter un auteur\u003c/em\u003e, and every button.\u003c/p\u003e","title":"Mini Library Course #8: Author CRUD, EasyAdmin Translations \u0026 Pushing to GitHub"},{"content":"In the previous chapter, we covered pull requests and forks. But one very important point was missing: how do you get the original project\u0026rsquo;s new changes into your fork?\nWhat you\u0026#39;ll learn\nWhy your fork falls behind the original project The role of the origin and upstream remotes Keep your fork up to date, and the full contribution cycle The problem Your fork is a copy of the project, taken at a given moment. While you work, other developers get their pull requests merged into the original project. Your fork doesn\u0026rsquo;t update itself.\nThe solution: the upstream remote Your local project knows two remote repositories:\nRemote Points to Used to origin Your fork Push your changes upstream The original project Get the latest changes Original project upstream Your fork origin Your machine local Fork Pull request git clone git push origin git pull upstream Pull from upstream, push to origin, and the pull request takes the last step. To see the configured remotes, open the project\u0026rsquo;s .git/config file, or run:\ngit remote -v # origin https://github.com/your-account/the-project.git (fetch) # origin https://github.com/your-account/the-project.git (push) # upstream https://github.com/owner/the-project.git (fetch) # upstream https://github.com/owner/the-project.git (push) Some tools, like GitHub Desktop, add upstream automatically. If it\u0026rsquo;s missing, add it by hand, with the original project\u0026rsquo;s URL:\ngit remote add upstream https://github.com/owner/the-project.git Get the changes git pull upstream master Replace master with the branch you want to pull.\nThe full cycle # Get the latest from the original project git pull upstream master # Send your changes to your fork git push origin feature/1 # Then open a pull request to the original project Remember the rule: pull from upstream, push to origin. Pushes always go to your fork, and the pull request is what brings the changes into the original project.\nTwo other ways to update\ngit pull does two things at once: it downloads (fetch) then merges (merge). You can also split them, to look at what\u0026rsquo;s coming before bringing it in:\ngit fetch upstream git log --oneline HEAD..upstream/main # the new commits git merge upstream/main And on GitHub, the Sync fork button on your fork\u0026rsquo;s page updates its main branch in one click. Then all that\u0026rsquo;s left is a plain git pull locally.\nAlso mind the branch name: many recent projects use main rather than master.\nExercise · Add the missing remote\ngit remote -v only shows origin. The original project is https://github.com/symfony/demo.git, and its main branch is main. Add upstream, then get its latest changes.\nShow the solution git remote add upstream https://github.com/symfony/demo.git git remote -v git pull upstream main What\u0026rsquo;s Next Create enough branches and the list grows fast. In the next chapter, we clean up branches.\nThis is Chapter 9 of the Git in Practice course. Follow along to learn how to use Git every day and as a team.\n","permalink":"https://naimidevslayer.com/en/cours/outils/git/git-en-pratique/09-fork-upstream/","summary":"\u003cp\u003eIn the previous chapter, we covered pull requests and forks. But one very important point was missing: \u003cstrong\u003ehow do you get the original project\u0026rsquo;s new changes\u003c/strong\u003e into your fork?\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/bqmxVf9fqnM?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eWhy your fork falls behind the original project\u003c/li\u003e\n\u003cli\u003eThe role of the \u003ccode\u003eorigin\u003c/code\u003e and \u003ccode\u003eupstream\u003c/code\u003e remotes\u003c/li\u003e\n\u003cli\u003eKeep your fork up to date, and the full contribution cycle\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"the-problem\"\u003eThe problem\u003c/h2\u003e\n\u003cp\u003eYour fork is a \u003cstrong\u003ecopy\u003c/strong\u003e of the project, taken at a given moment. While you work, other developers get their pull requests merged into the original project. Your fork doesn\u0026rsquo;t update itself.\u003c/p\u003e","title":"Git in Practice #9: Syncing Your Fork with upstream"},{"content":"A second round of LeetCode SQL problems! On the menu: joins, NULL, grouping, subqueries and a first look at IF and CASE.\nWhat you\u0026#39;ll learn\nHandle NULL in a condition Filter groups with HAVING Handle ties with a subquery Discover IF and CASE to transform values 1. Employee Bonus Tables:\nEmployee: empId (primary key), name, supervisor, salary Bonus: empId (foreign key), bonus Task: show the name and bonus of employees whose bonus is below 1000, including those with no bonus at all.\nFirst idea: a LEFT JOIN to keep every employee, then a filter on the bonus.\nSELECT e.name, b.bonus FROM Employee e LEFT JOIN Bonus b ON b.empId = e.empId WHERE b.bonus \u0026lt; 1000; That doesn\u0026rsquo;t work: we only get Dan (500). Brad and John, who have no bonus, are gone. Why? Their bonus is NULL, and NULL \u0026lt; 1000 is neither true nor false: the condition drops them.\nThe fix: include the NULLs explicitly with IS NULL.\nSELECT e.name, b.bonus FROM Employee e LEFT JOIN Bonus b ON b.empId = e.empId WHERE b.bonus \u0026lt; 1000 OR b.bonus IS NULL; To test for NULL, always write IS NULL or IS NOT NULL, never = NULL.\n2. Classes More Than 5 Students Table: Courses: student, class\nTask: show the classes that have at least 5 students.\nReasoning: group by class and count the rows in each group.\nSELECT class FROM Courses GROUP BY class HAVING COUNT(*) \u0026gt;= 5; 3. Not Boring Movies Table: Cinema: id (primary key), movie, description, rating\nTask: show the movies with an odd id whose description is not \u0026ldquo;boring\u0026rdquo;, sorted by rating, highest first.\nSELECT * FROM Cinema WHERE description NOT LIKE \u0026#39;boring\u0026#39; AND id % 2 \u0026lt;\u0026gt; 0 ORDER BY rating DESC; NOT LIKE compares strings. description \u0026lt;\u0026gt; 'boring' works too. id % 2 is the modulo: the remainder of the division by 2. If it\u0026rsquo;s not 0, the id is odd. 4. Customer Placing the Largest Number of Orders Table: Orders: order_number (primary key), customer_number\nTask: show the customer who placed the most orders. The data guarantees there\u0026rsquo;s only one.\nReasoning: group by customer, sort by number of orders, highest first, and keep the first.\nSELECT customer_number FROM Orders GROUP BY customer_number ORDER BY COUNT(*) DESC LIMIT 1; Going further: what about ties? LeetCode asks a bonus question: what if several customers shared the maximum number of orders? LIMIT 1 would keep only one.\nThe solution: keep every customer whose number of orders equals the maximum, computed by a subquery.\nSELECT customer_number FROM Orders GROUP BY customer_number HAVING COUNT(*) = ( SELECT COUNT(*) FROM Orders GROUP BY customer_number ORDER BY COUNT(*) DESC LIMIT 1 ); The subquery returns the maximum number of orders per customer, and HAVING keeps every customer who reaches it.\n5. Swap Salary Table: Salary: id (primary key), name, sex, salary. The sex column only holds 'm' or 'f'.\nTask: swap every value ('f' becomes 'm' and vice versa) with a single UPDATE query, without a temporary table.\nWith IF: IF(condition, value_if_true, value_if_false).\nUPDATE Salary SET sex = IF(sex = \u0026#39;f\u0026#39;, \u0026#39;m\u0026#39;, \u0026#39;f\u0026#39;); With CASE, more standard and available in every RDBMS:\nUPDATE Salary SET sex = CASE WHEN sex = \u0026#39;m\u0026#39; THEN \u0026#39;f\u0026#39; ELSE \u0026#39;m\u0026#39; END; IF and CASE weren\u0026rsquo;t part of the course, but they\u0026rsquo;re very handy. I encourage you to explore other MySQL functions: many of them will make your life easier in specific cases.\nExercise · Bonus: rank the salaries\nUsing the Employee table from exercise 1, show each employee\u0026rsquo;s name and a level column that\u0026rsquo;s 'high' if their salary is above 3000, 'medium' if it\u0026rsquo;s between 1000 and 3000, and 'low' otherwise.\nShow the solution SELECT name, CASE WHEN salary \u0026gt; 3000 THEN \u0026#39;high\u0026#39; WHEN salary \u0026gt;= 1000 THEN \u0026#39;medium\u0026#39; ELSE \u0026#39;low\u0026#39; END AS level FROM Employee; MySQL checks the WHENs in order and stops at the first true one: no need to write salary \u0026lt;= 3000 in the second.\nEnd of the course Well done, you\u0026rsquo;ve finished SQL from Zero to Pro! You can now create databases and tables, link them, manipulate and query data, and write subqueries and joins. To keep improving, carry on with LeetCode\u0026rsquo;s Easy then Medium problems.\nFound another solution to one of these problems? Share it in the comments under the video.\nThis is Chapter 9 of the SQL from Zero to Pro course. Follow along to learn SQL with MySQL, from the basics to joins.\n","permalink":"https://naimidevslayer.com/en/cours/bases-de-donnees/mysql/sql-de-zero-a-pro/09-exercices-partie-2/","summary":"\u003cp\u003eA second round of LeetCode SQL problems! On the menu: joins, \u003ccode\u003eNULL\u003c/code\u003e, grouping, subqueries and a first look at \u003ccode\u003eIF\u003c/code\u003e and \u003ccode\u003eCASE\u003c/code\u003e.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/PQRCtqb7blI?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eHandle \u003ccode\u003eNULL\u003c/code\u003e in a condition\u003c/li\u003e\n\u003cli\u003eFilter groups with \u003ccode\u003eHAVING\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003eHandle ties with a subquery\u003c/li\u003e\n\u003cli\u003eDiscover \u003ccode\u003eIF\u003c/code\u003e and \u003ccode\u003eCASE\u003c/code\u003e to transform values\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"1-employee-bonus\"\u003e1. Employee Bonus\u003c/h2\u003e\n\u003cp\u003e\u003cstrong\u003eTables:\u003c/strong\u003e\u003c/p\u003e","title":"SQL from Zero to Pro #9: Hands-On LeetCode Exercises (Part 2)"},{"content":"The Book entity is the heart of the project. In this chapter we configure every field of BookCrudController: text, relations, slug, the PDF file, the cover image, and the archived flag.\nWhat you\u0026#39;ll learn\nConfigure required text fields and rich text Link entities with AssociationField and __toString() Generate a slug automatically Upload a PDF with FileField and a cover with ImageField Generate the controller as for the others (symfony console make:admin:crud, then choose Book), add it to the menu, and let\u0026rsquo;s fill configureFields().\nTitle and Summary TextField::new(\u0026#39;title\u0026#39;)-\u0026gt;setLabel(\u0026#39;Titre\u0026#39;)-\u0026gt;setRequired(true), TextEditorField::new(\u0026#39;summary\u0026#39;)-\u0026gt;setLabel(\u0026#39;Résumé\u0026#39;)-\u0026gt;setRequired(true), The summary uses TextEditorField for rich text. Both fields are required.\nAuthor and Categories The relations use AssociationField, which displays a select list of the related entities:\nAssociationField::new(\u0026#39;author\u0026#39;, \u0026#39;Auteur\u0026#39;), AssociationField::new(\u0026#39;categories\u0026#39;, \u0026#39;Catégories\u0026#39;), \u0026ldquo;Could not convert … to string\u0026rdquo; Refresh and EasyAdmin throws an error: it doesn\u0026rsquo;t know how to display an Author in the list. The fix is to add a __toString() method to the entity:\n// src/Entity/Author.php public function __toString() { return $this-\u0026gt;getFirstName() . \u0026#39; \u0026#39; . $this-\u0026gt;getLastName(); } Same error for categories, same fix:\n// src/Entity/Category.php public function __toString(): string { return $this-\u0026gt;getCategoryName() ?? \u0026#39;\u0026#39;; } Common mistake\n__toString() must always return a string. But categoryName is nullable: without the ?? '', a category with no name crashes the whole list with a TypeError. On the Author side, concatenating with . already turns null into an empty string, so no problem there.\nPlaceholders By default, the author select shows the first author, which is confusing. We add a placeholder with setFormTypeOption(). The syntax differs between the two fields because the categories field is ManyToMany (a multiple select):\nAssociationField::new(\u0026#39;author\u0026#39;, \u0026#39;Auteur\u0026#39;) -\u0026gt;setRequired(true) -\u0026gt;setFormTypeOption(\u0026#39;placeholder\u0026#39;, \u0026#39;Choisissez un auteur\u0026#39;), AssociationField::new(\u0026#39;categories\u0026#39;, \u0026#39;Catégories\u0026#39;) -\u0026gt;setRequired(true) -\u0026gt;setFormTypeOption(\u0026#39;attr\u0026#39;, [\u0026#39;placeholder\u0026#39; =\u0026gt; \u0026#39;Choisissez une ou plusieurs catégorie(s)\u0026#39;]), The Slug EasyAdmin has a SlugField. Its source is set with setTargetFieldName(): here, the combination of title and author.\nSlugField::new(\u0026#39;bookSlug\u0026#39;)-\u0026gt;setTargetFieldName([\u0026#39;title\u0026#39;, \u0026#39;author\u0026#39;]), The PDF File: FileField FileField::new(\u0026#39;bookFileName\u0026#39;, \u0026#39;Livre\u0026#39;) -\u0026gt;setUploadDir(\u0026#39;public/uploads/books/files/\u0026#39; . $path . \u0026#39;/\u0026#39;) -\u0026gt;setBasePath(\u0026#39;uploads/books/files/\u0026#39; . $path . \u0026#39;/\u0026#39;) -\u0026gt;setUploadedFileNamePattern(\u0026#39;[randomhash].[extension]\u0026#39;) -\u0026gt;setRequired(true) -\u0026gt;maxSize(\u0026#39;7M\u0026#39;) -\u0026gt;mimeTypes(\u0026#39;.pdf\u0026#39;), Option Role setUploadDir() Where the file is stored on disk setBasePath() The public URL path (same thing, without public/) setUploadedFileNamePattern() A random name, to avoid collisions maxSize() Rejects files that are too big (no 1 GB uploads!) mimeTypes() The file picker only shows PDFs Organizing uploads by month Rather than putting every file in the same folder, I build a small path from the year and month of the upload, at the top of configureFields():\n$now = new \\DateTimeImmutable(); $path = $now-\u0026gt;format(\u0026#39;Y\u0026#39;) . \u0026#39;_\u0026#39; . $now-\u0026gt;format(\u0026#39;m\u0026#39;); // e.g. 2026_08 Files end up in public/uploads/books/files/2026_08/. The files/ folder separates the books from the covers.\nThis system has a flaw that we\u0026rsquo;ll discover and fix in chapter 11.\nThe Cover: ImageField Same options, with ImageField, an images/ folder, a 2 MB limit, image MIME types, and a custom error message:\nImageField::new(\u0026#39;coverImageName\u0026#39;, \u0026#39;Couverture\u0026#39;) -\u0026gt;setUploadDir(\u0026#39;public/uploads/books/images/\u0026#39; . $path . \u0026#39;/\u0026#39;) -\u0026gt;setBasePath(\u0026#39;uploads/books/images/\u0026#39; . $path . \u0026#39;/\u0026#39;) -\u0026gt;setUploadedFileNamePattern(\u0026#39;[randomhash].[extension]\u0026#39;) -\u0026gt;setRequired(true) -\u0026gt;maxSize(\u0026#39;2M\u0026#39;, \u0026#39;Le fichier \u0026#34;{{ name }}\u0026#34; dépasse la taille maximale autorisée ({{ limit }} {{ suffix }}).\u0026#39;) -\u0026gt;mimeTypes(\u0026#39;image/jpeg,image/png,image/webp\u0026#39;), Archived or Not BooleanField::new(\u0026#39;isArchived\u0026#39;, \u0026#39;Archivé\u0026#39;), Testing Create a book: title, summary, author, several categories, a PDF and a cover. The file picker only shows PDFs for the book and only images for the cover. After saving, the files are in public/uploads/books/files/ and public/uploads/books/images/.\nThree things still look wrong in the list:\nthe summary shows raw HTML tags the categories only show a count the book shows the hashed file name That\u0026rsquo;s for the next chapter.\nA 5 MB PDF rejected while the limit is 7 MB?\nBefore EasyAdmin even checks the size, PHP applies its own limits, set in php.ini:\nupload_max_filesize = 8M post_max_size = 10M By default, upload_max_filesize is often 2 MB. Set it above your maxSize() limit, with post_max_size a bit larger, then restart WAMP\u0026rsquo;s services. Check the active values with php -i | grep upload_max.\nGoing further\nFor more advanced uploads (image resizing, cloud storage), look at VichUploaderBundle or Flysystem. For this project, EasyAdmin\u0026rsquo;s built-in fields are more than enough.\nRecap AssociationField for relations, with __toString() in the related entities setFormTypeOption() for placeholders SlugField + setTargetFieldName() for automatic slugs FileField and ImageField for uploads: folder, path, name pattern, size and type Exercise · Lighter covers\nLimit covers to 1 MB and also accept GIF images.\nShow the solution ImageField::new(\u0026#39;coverImageName\u0026#39;, \u0026#39;Couverture\u0026#39;) // … same options as before … -\u0026gt;maxSize(\u0026#39;1M\u0026#39;, \u0026#39;The file \u0026#34;{{ name }}\u0026#34; is too large ({{ limit }} {{ suffix }} max).\u0026#39;) -\u0026gt;mimeTypes(\u0026#39;image/jpeg,image/png,image/webp,image/gif\u0026#39;), This is Chapter 9 of the Mini Library course. Follow along to build a complete Symfony 8 + EasyAdmin digital library application from scratch.\n","permalink":"https://naimidevslayer.com/en/cours/developpement-web/symfony-8/mini-bibliotheque/09-book-crud-fields/","summary":"\u003cp\u003eThe \u003cstrong\u003eBook\u003c/strong\u003e entity is the heart of the project. In this chapter we configure every field of \u003ccode\u003eBookCrudController\u003c/code\u003e: text, relations, slug, the PDF file, the cover image, and the archived flag.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/AiANESc4Up4?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eConfigure required text fields and rich text\u003c/li\u003e\n\u003cli\u003eLink entities with \u003ccode\u003eAssociationField\u003c/code\u003e and \u003ccode\u003e__toString()\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003eGenerate a slug automatically\u003c/li\u003e\n\u003cli\u003eUpload a PDF with \u003ccode\u003eFileField\u003c/code\u003e and a cover with \u003ccode\u003eImageField\u003c/code\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003cp\u003eGenerate the controller as for the others (\u003ccode\u003esymfony console make:admin:crud\u003c/code\u003e, then choose Book), add it to the menu, and let\u0026rsquo;s fill \u003ccode\u003econfigureFields()\u003c/code\u003e.\u003c/p\u003e","title":"Mini Library Course #9: Book CRUD in EasyAdmin: Fields, Relations, Files \u0026 Images"},{"content":"Picture yourself working in an agile team: after three sprints, you\u0026rsquo;ve handled 25 tickets, so you\u0026rsquo;ve created 25 branches. Run git branch and you get an endless list. Always remember to clean up your branches, locally and on the server.\nWhat you\u0026#39;ll learn\nDelete a merged branch, locally and on the server Force-delete an unmerged branch Forget branches deleted by others Starting point git branch # feature/1 # feature/2 # feature/3 # feature/4 # * master The server has the same list.\nDelete a merged branch feature/4 has been approved and merged into master. We delete it locally:\ngit branch -d feature/4 # Deleted branch feature/4 Then on the server:\ngit push origin --delete feature/4 Refresh the repository page: the branch is gone.\nCareful: git push origin feature/4, without --delete, pushes the branch instead of deleting it. The older syntax git push origin :feature/4 also deletes it.\nDelete an unmerged branch feature/3 was not merged, and we still want to delete it:\ngit branch -d feature/3 # error: the branch \u0026#39;feature/3\u0026#39; is not fully merged. Git refuses: it thinks you forgot to merge the branch, and protects you from losing work. If you\u0026rsquo;re sure, force the deletion with -D (capital D, for delete force):\ngit branch -D feature/3 # Deleted branch feature/3 git push origin --delete feature/3 A bit more tidying When someone else deletes a branch on the server, your local repository keeps a trace of it (origin/feature/x). To remove it:\ngit fetch --prune Finding branches to delete\nTo list branches already merged into the current branch, so safe to delete with -d:\ngit branch --merged And to have every git fetch or git pull tidy up automatically, without thinking about --prune:\ngit config --global fetch.prune true Tip\nOn GitHub, the Automatically delete head branches option (Settings → General) deletes the branch on the server as soon as its pull request is merged. Only the local cleanup is left to you.\nRecap Command Role git branch -d \u0026lt;branch\u0026gt; Delete a merged local branch git branch -D \u0026lt;branch\u0026gt; Force-delete an unmerged local branch git push origin --delete \u0026lt;branch\u0026gt; Delete a branch on the server git fetch --prune Forget branches deleted from the server Exercise · The big cleanup\nThe feature/login branch is merged. The test/trial branch isn\u0026rsquo;t, but you don\u0026rsquo;t want it anymore. Both exist locally and on the server. Delete them everywhere.\nShow the solution git branch -d feature/login git push origin --delete feature/login git branch -D test/trial git push origin --delete test/trial -d is enough for the merged branch. For test/trial, Git would refuse -d: you need -D.\nWhat\u0026rsquo;s Next Last chapter: git diff, to check exactly what you changed before committing.\nThis is Chapter 10 of the Git in Practice course. Follow along to learn how to use Git every day and as a team.\n","permalink":"https://naimidevslayer.com/en/cours/outils/git/git-en-pratique/10-nettoyage-branches/","summary":"\u003cp\u003ePicture yourself working in an agile team: after three sprints, you\u0026rsquo;ve handled 25 tickets, so you\u0026rsquo;ve created \u003cstrong\u003e25 branches\u003c/strong\u003e. Run \u003ccode\u003egit branch\u003c/code\u003e and you get an endless list. Always remember to \u003cstrong\u003eclean up your branches\u003c/strong\u003e, locally and on the server.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/HducC-0PJF4?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e","title":"Git in Practice #10: Cleaning Up Branches Locally and on the Server"},{"content":"Our Book CRUD works, but the list is hard to read: raw HTML in the summary, a bare number for categories, and a hashed file name for the book. Before fixing that, we push our work, with one important precaution.\nWhat you\u0026#39;ll learn\nKeep uploaded files out of Git Declare two EasyAdmin fields for the same property Display HTML, badges and links in the list Choose between onlyOnForms(), hideOnForm() and hideOnIndex() Don\u0026rsquo;t Push the Uploads git status Along with our CRUD controllers, there\u0026rsquo;s a new folder: public/uploads/. Uploaded files have nothing to do in Git, so we add the folder to .gitignore:\n/public/uploads/ Check again with git status: the folder is gone. Then:\ngit add . git commit -m \u0026#34;book crud\u0026#34; git push origin main The Idea: Two Fields for the Same Property This is the key point of the chapter. You can declare two EasyAdmin fields for the same entity property, and decide on which pages each one appears:\nonlyOnForms(): only on the create and edit forms hideOnForm(): everywhere except the forms hideOnIndex(): everywhere except the list So we keep the field we need for editing, and add another one, configured for display.\n1. The Summary On the forms, we keep the rich text editor:\nTextEditorField::new(\u0026#39;summary\u0026#39;)-\u0026gt;setLabel(\u0026#39;Résumé\u0026#39;)-\u0026gt;setRequired(true)-\u0026gt;onlyOnForms(), For display, we use a TextareaField that renders HTML. With formatValue(), we show a link that opens the summary in a modal window:\nTextareaField::new(\u0026#39;summary\u0026#39;, \u0026#39;Résumé\u0026#39;) -\u0026gt;renderAsHtml() -\u0026gt;hideOnForm() -\u0026gt;formatValue(function ($value, $entity) { if (!$value) return \u0026#39;\u0026#39;; $id = \u0026#39;modal-\u0026#39; . $entity-\u0026gt;getId(); return sprintf( \u0026#39;\u0026lt;a href=\u0026#34;#\u0026#34; data-bs-toggle=\u0026#34;modal\u0026#34; data-bs-target=\u0026#34;#%s\u0026#34;\u0026gt;📄 Voir le résumé\u0026lt;/a\u0026gt; \u0026lt;div class=\u0026#34;modal fade\u0026#34; id=\u0026#34;%s\u0026#34; tabindex=\u0026#34;-1\u0026#34;\u0026gt; \u0026lt;div class=\u0026#34;modal-dialog\u0026#34;\u0026gt;\u0026lt;div class=\u0026#34;modal-content\u0026#34;\u0026gt; \u0026lt;div class=\u0026#34;modal-header\u0026#34;\u0026gt; \u0026lt;h5 class=\u0026#34;modal-title\u0026#34;\u0026gt;Résumé\u0026lt;/h5\u0026gt; \u0026lt;button type=\u0026#34;button\u0026#34; class=\u0026#34;btn-close\u0026#34; data-bs-dismiss=\u0026#34;modal\u0026#34;\u0026gt;\u0026lt;/button\u0026gt; \u0026lt;/div\u0026gt; \u0026lt;div class=\u0026#34;modal-body text-break\u0026#34;\u0026gt;%s\u0026lt;/div\u0026gt; \u0026lt;/div\u0026gt;\u0026lt;/div\u0026gt; \u0026lt;/div\u0026gt;\u0026#39;, $id, $id, $value ); }), 2. The Categories Same idea: the form field stays as it is with onlyOnForms(), and a second field shows the category names as badges, in a modal:\nAssociationField::new(\u0026#39;categories\u0026#39;, \u0026#39;Catégories\u0026#39;) -\u0026gt;renderAsHtml() -\u0026gt;hideOnForm() -\u0026gt;formatValue(function ($_, $entity) { $categories = $entity-\u0026gt;getCategories(); if ($categories-\u0026gt;isEmpty()) return \u0026#39;\u0026#39;; $id = \u0026#39;modal-categories-\u0026#39; . $entity-\u0026gt;getId(); $badges = implode(\u0026#39; \u0026#39;, array_map( fn ($category) =\u0026gt; sprintf( \u0026#39;\u0026lt;span class=\u0026#34;badge badge-pill badge-info\u0026#34;\u0026gt;%s\u0026lt;/span\u0026gt;\u0026#39;, htmlspecialchars($category-\u0026gt;getCategoryName()) ), $categories-\u0026gt;toArray() )); return sprintf( \u0026#39;\u0026lt;a href=\u0026#34;#\u0026#34; data-bs-toggle=\u0026#34;modal\u0026#34; data-bs-target=\u0026#34;#%s\u0026#34;\u0026gt;🏷️ %d catégorie(s)\u0026lt;/a\u0026gt; \u0026lt;div class=\u0026#34;modal fade\u0026#34; id=\u0026#34;%s\u0026#34; tabindex=\u0026#34;-1\u0026#34;\u0026gt;…%s…\u0026lt;/div\u0026gt;\u0026#39;, $id, $categories-\u0026gt;count(), $id, $badges ); }), Click 7 catégorie(s) and the modal lists all seven.\n3. The PDF File The FileField is hidden from the list with hideOnIndex(), and a TextField displays a \u0026ldquo;Voir le PDF\u0026rdquo; link instead:\nTextField::new(\u0026#39;bookFileName\u0026#39;, \u0026#39;Livre\u0026#39;) -\u0026gt;renderAsHtml() -\u0026gt;hideOnForm() -\u0026gt;formatValue(function ($value) use ($path) { if (!$value) return \u0026#39;\u0026#39;; return sprintf( \u0026#39;\u0026lt;a href=\u0026#34;/uploads/books/files/%s/%s\u0026#34; target=\u0026#34;_blank\u0026#34;\u0026gt;📄 Voir le PDF\u0026lt;/a\u0026gt;\u0026#39;, $path, $value ); }), Click it, and the PDF opens in a new tab.\nTwo Solutions, to Sum Up Use formatValue() on the same field to change how it\u0026rsquo;s displayed Or use two fields for the same property, one for forms and one for display Two Problems Left Looking at the database, two things are wrong:\nbook_file_path and cover_image_path are empty (NULL). Delete a book and its row disappears, but the PDF and the image stay on disk. Over time, that\u0026rsquo;s a storage problem. We fix both in the next chapter.\nHTML that\u0026#39;s easier to maintain\nWriting HTML inside sprintf() quickly gets unreadable. EasyAdmin lets you hand a field\u0026rsquo;s display over to a Twig template:\nTextareaField::new(\u0026#39;summary\u0026#39;, \u0026#39;Résumé\u0026#39;) -\u0026gt;hideOnForm() -\u0026gt;setTemplatePath(\u0026#39;admin/field/summary.html.twig\u0026#39;), {# templates/admin/field/summary.html.twig #} \u0026lt;a href=\u0026#34;#\u0026#34; data-bs-toggle=\u0026#34;modal\u0026#34; data-bs-target=\u0026#34;#modal-{{ entity.instance.id }}\u0026#34;\u0026gt;📄 Show summary\u0026lt;/a\u0026gt; In this template, field.value holds the value and entity.instance the Book object. And Twig escapes HTML by default, which protects against XSS.\nExercise · A more readable list\nThe slug adds nothing to the book list. Hide it on the index page, while keeping it in the forms and the detail view.\nShow the solution SlugField::new(\u0026#39;bookSlug\u0026#39;) -\u0026gt;setTargetFieldName([\u0026#39;title\u0026#39;, \u0026#39;author\u0026#39;]) -\u0026gt;hideOnIndex(), This is Chapter 10 of the Mini Library course. Follow along to build a complete Symfony 8 + EasyAdmin digital library application from scratch.\n","permalink":"https://naimidevslayer.com/en/cours/developpement-web/symfony-8/mini-bibliotheque/10-easyadmin-display-fixes/","summary":"\u003cp\u003eOur Book CRUD works, but the list is hard to read: raw HTML in the summary, a bare number for categories, and a hashed file name for the book. Before fixing that, we push our work, with one important precaution.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/DeYzT4lLUZQ?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e","title":"Mini Library Course #10: Fix the EasyAdmin Display: HTML Rendering \u0026 Clickable Links"},{"content":"As its name suggests, git diff shows the difference: the exact changes you made in each file.\nWhat you\u0026#39;ll learn\nRead git diff output: the + and - signs Review your changes before every commit Compare what\u0026rsquo;s staged with what isn\u0026rsquo;t An example In a file, we delete one line, change another and add a new one. git status only says the file is modified. To see the details:\ngit diff -a deleted line -the old version of the line +the new version of the line +an added line Lines starting with - (in red) were removed. Lines starting with + (in green) were added. A changed line shows up as a removal of the old version, followed by an addition of the new one. Why use it before every commit It\u0026rsquo;s the best way to spot what doesn\u0026rsquo;t belong in your commit:\nspaces or line breaks added by accident; changes added automatically by your editor; leftover debugging. Nothing serious, but it makes the commit less clean and harder to review. Personally, I run git diff before every commit.\nUseful variants Command What it shows git diff Changes not yet staged with git add git diff --staged Changes already staged, which will go into the next commit git diff \u0026lt;file\u0026gt; Changes in a single file Comparing other things\ngit diff can compare far more than your working directory:\nCommand What it compares git diff HEAD Everything changed since the last commit, staged or not git diff --stat A summary: changed files and line counts git diff main..feature/1 Two branches git diff HEAD~1 Your folder and the commit before last And in VS Code, the Source Control tab shows the same differences side by side: clicking a changed file opens the comparison.\nExercise · What goes into the commit\nYou ran git add on two files, then changed one of them again. Which command shows exactly what will go into your next commit?\nShow the solution git diff --staged A plain git diff only shows the latest change, not yet staged. It won\u0026rsquo;t go into the commit until you run git add again.\nEnd of the course Well done, you\u0026rsquo;ve finished Git in Practice! You can now install Git, clone and initialize a project, work with branches, set work aside, write clean commits, contribute with forks and pull requests, and keep your repository tidy.\nThis is Chapter 11 of the Git in Practice course. Follow along to learn how to use Git every day and as a team.\n","permalink":"https://naimidevslayer.com/en/cours/outils/git/git-en-pratique/11-git-diff/","summary":"\u003cp\u003eAs its name suggests, \u003cstrong\u003e\u003ccode\u003egit diff\u003c/code\u003e\u003c/strong\u003e shows \u003cstrong\u003ethe difference\u003c/strong\u003e: the exact changes you made in each file.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/hhZ4wfGo-G0?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eRead \u003ccode\u003egit diff\u003c/code\u003e output: the \u003ccode\u003e+\u003c/code\u003e and \u003ccode\u003e-\u003c/code\u003e signs\u003c/li\u003e\n\u003cli\u003eReview your changes before every commit\u003c/li\u003e\n\u003cli\u003eCompare what\u0026rsquo;s staged with what isn\u0026rsquo;t\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"an-example\"\u003eAn example\u003c/h2\u003e\n\u003cp\u003eIn a file, we \u003cstrong\u003edelete\u003c/strong\u003e one line, \u003cstrong\u003echange\u003c/strong\u003e another and \u003cstrong\u003eadd\u003c/strong\u003e a new one. \u003ccode\u003egit status\u003c/code\u003e only says the file is modified. To see the details:\u003c/p\u003e","title":"Git in Practice #11: Reviewing Your Changes with git diff"},{"content":"We left two problems open: the file paths aren\u0026rsquo;t saved, and deleted books leave their files on disk. There\u0026rsquo;s also a hidden bug in our \u0026ldquo;year_month\u0026rdquo; folder system. This chapter fixes all three.\nWhat you\u0026#39;ll learn\nSpot the hidden bug of a path computed at display time Save each file\u0026rsquo;s path in the database at upload time Override persistEntity, updateEntity and deleteEntity Delete old files without any risk of data loss The Hidden Bug in Our Path System In chapter 9, we computed the upload folder from the current date, directly in configureFields():\n$path = $now-\u0026gt;format(\u0026#39;Y\u0026#39;) . \u0026#39;_\u0026#39; . $now-\u0026gt;format(\u0026#39;m\u0026#39;); That\u0026rsquo;s fine for uploading, but we also used it to display files. So in September, the app looks for August\u0026rsquo;s files in the 2026_09 folder… and can\u0026rsquo;t find them. Change the month by hand to simulate it: the cover disappears, and the PDF link is broken.\nThe fix: save the path of each file in the database when it\u0026rsquo;s uploaded (bookFilePath, coverImagePath), and use that to display it.\nThe Plan AbstractCrudController lets us override what happens when an entity is saved:\nMethod When What we do persistEntity() Creation Fill in the two paths updateEntity() Update If a file changed, delete the old one and save the new path deleteEntity() Deletion Delete the PDF and the image from disk Getting the Project Directory To delete files, we need their absolute path, so we inject the kernel.project_dir parameter into the constructor:\npublic function __construct( #[Autowire(param: \u0026#39;kernel.project_dir\u0026#39;)] private readonly string $projectDir, ) {} Two Small Helpers private function currentUploadPath(): string { $now = new \\DateTimeImmutable(); return $now-\u0026gt;format(\u0026#39;Y\u0026#39;) . \u0026#39;_\u0026#39; . $now-\u0026gt;format(\u0026#39;m\u0026#39;); } private function resolveFilePath(string $subDir, ?string $path, ?string $fileName): ?string { if (!$path || !$fileName) { return null; } return $this-\u0026gt;projectDir . \u0026#39;/public/uploads/\u0026#39; . $subDir . \u0026#39;/\u0026#39; . $path . \u0026#39;/\u0026#39; . $fileName; } Creation: persistEntity() public function persistEntity(EntityManagerInterface $entityManager, object $entityInstance): void { if ($entityInstance instanceof Book) { $path = $this-\u0026gt;currentUploadPath(); if ($entityInstance-\u0026gt;getBookFileName()) { $entityInstance-\u0026gt;setBookFilePath($path); } if ($entityInstance-\u0026gt;getCoverImageName()) { $entityInstance-\u0026gt;setCoverImagePath($path); } } $entityManager-\u0026gt;persist($entityInstance); $entityManager-\u0026gt;flush(); } Update: updateEntity() Doctrine\u0026rsquo;s Unit of Work gives us the original values of the entity, so we can tell which files changed:\npublic function updateEntity(EntityManagerInterface $entityManager, object $entityInstance): void { $filesToDelete = []; if ($entityInstance instanceof Book) { $original = $entityManager-\u0026gt;getUnitOfWork()-\u0026gt;getOriginalEntityData($entityInstance); $path = $this-\u0026gt;currentUploadPath(); if (($original[\u0026#39;bookFileName\u0026#39;] ?? null) !== $entityInstance-\u0026gt;getBookFileName()) { $filesToDelete[] = $this-\u0026gt;resolveFilePath(\u0026#39;books/files\u0026#39;, $original[\u0026#39;bookFilePath\u0026#39;] ?? null, $original[\u0026#39;bookFileName\u0026#39;] ?? null); $entityInstance-\u0026gt;setBookFilePath($path); } if (($original[\u0026#39;coverImageName\u0026#39;] ?? null) !== $entityInstance-\u0026gt;getCoverImageName()) { $filesToDelete[] = $this-\u0026gt;resolveFilePath(\u0026#39;books/images\u0026#39;, $original[\u0026#39;coverImagePath\u0026#39;] ?? null, $original[\u0026#39;coverImageName\u0026#39;] ?? null); $entityInstance-\u0026gt;setCoverImagePath($path); } $filesToDelete = array_filter($filesToDelete); } $entityManager-\u0026gt;persist($entityInstance); $entityManager-\u0026gt;flush(); foreach ($filesToDelete as $file) { if (is_file($file)) { @unlink($file); } } } The old files are only deleted after a successful flush(), so a failed save never loses data.\nDeletion: deleteEntity() public function deleteEntity(EntityManagerInterface $entityManager, object $entityInstance): void { $filesToDelete = []; if ($entityInstance instanceof Book) { $filesToDelete = array_filter([ $this-\u0026gt;resolveFilePath(\u0026#39;books/files\u0026#39;, $entityInstance-\u0026gt;getBookFilePath(), $entityInstance-\u0026gt;getBookFileName()), $this-\u0026gt;resolveFilePath(\u0026#39;books/images\u0026#39;, $entityInstance-\u0026gt;getCoverImagePath(), $entityInstance-\u0026gt;getCoverImageName()), ]); } $entityManager-\u0026gt;remove($entityInstance); $entityManager-\u0026gt;flush(); foreach ($filesToDelete as $file) { if (is_file($file)) { @unlink($file); } } } Displaying with the Saved Paths The \u0026ldquo;Voir le PDF\u0026rdquo; link now uses getBookFilePath() instead of the computed path:\nTextField::new(\u0026#39;bookFileName\u0026#39;, \u0026#39;Livre\u0026#39;) -\u0026gt;renderAsHtml() -\u0026gt;hideOnForm() -\u0026gt;formatValue(function ($value, $entity) { if (!$value) return \u0026#39;\u0026#39;; return sprintf( \u0026#39;\u0026lt;a href=\u0026#34;/uploads/books/files/%s/%s\u0026#34; target=\u0026#34;_blank\u0026#34;\u0026gt;📄 Voir le PDF\u0026lt;/a\u0026gt;\u0026#39;, $entity-\u0026gt;getBookFilePath(), $value ); }), For the cover, we keep the ImageField but build the thumbnail ourselves with formatValue(). Because we return our own HTML, the field template must switch from crud/field/image to crud/field/text. We keep EasyAdmin\u0026rsquo;s lightbox, so clicking the thumbnail still shows the full image:\nImageField::new(\u0026#39;coverImageName\u0026#39;, \u0026#39;Couverture\u0026#39;) // ... same upload options as before ... -\u0026gt;setTemplateName(\u0026#39;crud/field/text\u0026#39;) -\u0026gt;formatValue(function ($value, $entity) { if (!$value) return \u0026#39;\u0026#39;; $url = sprintf(\u0026#39;/uploads/books/images/%s/%s\u0026#39;, $entity-\u0026gt;getCoverImagePath(), $value); $lightboxId = \u0026#39;ea-lightbox-cover-\u0026#39; . $entity-\u0026gt;getId(); return sprintf( \u0026#39;\u0026lt;a href=\u0026#34;#\u0026#34; class=\u0026#34;ea-lightbox-thumbnail\u0026#34; data-ea-lightbox-content-selector=\u0026#34;#%s\u0026#34;\u0026gt; \u0026lt;img src=\u0026#34;%s\u0026#34; class=\u0026#34;img-fluid\u0026#34;\u0026gt; \u0026lt;/a\u0026gt; \u0026lt;div id=\u0026#34;%s\u0026#34; class=\u0026#34;ea-lightbox\u0026#34;\u0026gt;\u0026lt;img src=\u0026#34;%s\u0026#34;\u0026gt;\u0026lt;/div\u0026gt;\u0026#39;, $lightboxId, $url, $lightboxId, $url ); }), Testing Display: the cover and the PDF show up correctly. Delete: the image and the PDF are removed from public/uploads/. Update with new files: only the new files remain on disk. A Challenge for You Edit a book, change only the title, and save. EasyAdmin complains that the file fields are empty: on the edit page they don\u0026rsquo;t know the file already exists, and they\u0026rsquo;re marked as required. Think about how to fix it. The solution is in the next chapter.\nAnother approach: Doctrine events\nHere, the file logic lives in the CRUD controller, so it only applies in the admin. If a book is one day deleted elsewhere (a console command, an API…), its files will stay on disk.\nFor a rule that applies everywhere, you can move it into a Doctrine listener, triggered on every Book deletion, wherever it comes from:\nuse Doctrine\\Bundle\\DoctrineBundle\\Attribute\\AsEntityListener; use Doctrine\\ORM\\Events; #[AsEntityListener(event: Events::postRemove, entity: Book::class)] final class BookFileCleaner { public function __invoke(Book $book): void { // delete the PDF and the cover from disk } } postRemove runs after the database deletion: just like our deleteEntity(), the files are only touched once the row is really gone.\nExercise · Why after the flush?\nIn updateEntity() and deleteEntity(), files are deleted after flush(), never before. What would happen the other way round if saving to the database failed?\nShow the solution The files would already be gone, but the database would still hold the book with its old paths. The result: a book pointing to a PDF and a cover that no longer exist, with no way to get them back.\nBy deleting after a successful flush(), the worst case is an orphan file on disk: a bit of wasted space, but no broken data.\nThis is Chapter 11 of the Mini Library course. Follow along to build a complete Symfony 8 + EasyAdmin digital library application from scratch.\n","permalink":"https://naimidevslayer.com/en/cours/developpement-web/symfony-8/mini-bibliotheque/11-easyadmin-file-uploads/","summary":"\u003cp\u003eWe left two problems open: the \u003cstrong\u003efile paths aren\u0026rsquo;t saved\u003c/strong\u003e, and \u003cstrong\u003edeleted books leave their files on disk\u003c/strong\u003e. There\u0026rsquo;s also a hidden bug in our \u0026ldquo;year_month\u0026rdquo; folder system. This chapter fixes all three.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/obbayz6mEGo?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e\n  \u003cul\u003e\n\u003cli\u003eSpot the hidden bug of a path computed at display time\u003c/li\u003e\n\u003cli\u003eSave each file\u0026rsquo;s path in the database at upload time\u003c/li\u003e\n\u003cli\u003eOverride \u003ccode\u003epersistEntity\u003c/code\u003e, \u003ccode\u003eupdateEntity\u003c/code\u003e and \u003ccode\u003edeleteEntity\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003eDelete old files without any risk of data loss\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/aside\u003e\n\n\u003ch2 id=\"the-hidden-bug-in-our-path-system\"\u003eThe Hidden Bug in Our Path System\u003c/h2\u003e\n\u003cp\u003eIn chapter 9, we computed the upload folder from the \u003cstrong\u003ecurrent date\u003c/strong\u003e, directly in \u003ccode\u003econfigureFields()\u003c/code\u003e:\u003c/p\u003e","title":"Mini Library Course #11: File Uploads Done Right in EasyAdmin"},{"content":"Last chapter ended with a challenge: our file and image fields are required, so when you edit a book, EasyAdmin complains they\u0026rsquo;re empty, even though the files exist. This is a classic EasyAdmin gotcha. Let\u0026rsquo;s fix it properly, then clean up the admin\u0026rsquo;s styling with a custom CSS file.\nWhat you\u0026#39;ll learn\nUnderstand why a required file field blocks editing Use $pageName to adapt a field to the current page Load your own CSS (and JS) in EasyAdmin with configureAssets() Why It Happens On the edit page, an upload field doesn\u0026rsquo;t know that a file is already stored for this entity. If it\u0026rsquo;s marked as required, the form expects a new file every time.\nWhat we want:\nRequired when creating a book Optional when editing one, without losing the existing file Using $pageName configureFields() receives the current page as $pageName. Dump it on the create page and you\u0026rsquo;ll see new; on the edit page, edit. That\u0026rsquo;s all we need. Instead of setRequired(true), we make it depend on the page:\nFileField::new(\u0026#39;bookFileName\u0026#39;, \u0026#39;Livre\u0026#39;) // ... upload options ... -\u0026gt;setRequired($pageName === Crud::PAGE_NEW), ImageField::new(\u0026#39;coverImageName\u0026#39;, \u0026#39;Couverture\u0026#39;) // ... upload options ... -\u0026gt;setRequired($pageName === Crud::PAGE_NEW), Test it: both fields are required on the create page, and optional on the edit page. Change the title, save, and the book keeps its PDF and its cover.\nCleaning Up the Error Style Now try uploading a file that\u0026rsquo;s too big. The error message appears, which is good, but the whole fieldset gets a red border that doesn\u0026rsquo;t look great.\nInspect the page to find the class: form-fieldset has-fieldset-error. Then create public/custom.css:\n.form-fieldset.has-fieldset-error { border: none; box-shadow: none; } Loading CSS in EasyAdmin: configureAssets() EasyAdmin doesn\u0026rsquo;t use our base.html.twig, so we add the file through the dashboard. In DashboardController, override configureAssets():\npublic function configureAssets(): Assets { return Assets::new()-\u0026gt;addCssFile(\u0026#39;custom.css\u0026#39;); } The path is relative to public/. Test again with a large file: the error message is still there, without the red border.\nNeed JavaScript too? Use addJsFile() the same way: Assets::new()-\u0026gt;addJsFile('admin.js').\nCommon mistake\nYour CSS changes nothing? The browser often keeps the old version in cache. Press Ctrl + Shift + R to reload the page without cache. Also check, in the developer tools\u0026rsquo; Network tab, that custom.css is actually loaded (status 200, not 404).\nTip\nFor a style that only concerns one CRUD, define configureAssets() in that CRUD controller rather than in the dashboard: the file is then only loaded on its pages.\nRecap $pageName === Crud::PAGE_NEW makes upload fields required only on creation Global admin styles go in a CSS file in public/ configureAssets() with addCssFile() or addJsFile() loads them in EasyAdmin Exercise · A bit of JavaScript\nCreate a public/admin.js file that prints \u0026ldquo;Admin loaded\u0026rdquo; in the browser console, and load it across the whole admin.\nShow the solution // public/admin.js console.log(\u0026#39;Admin loaded\u0026#39;); public function configureAssets(): Assets { return Assets::new() -\u0026gt;addCssFile(\u0026#39;custom.css\u0026#39;) -\u0026gt;addJsFile(\u0026#39;admin.js\u0026#39;); } Open the browser console (F12) on any admin page: the message shows up.\nThis is Chapter 12 of the Mini Library course. Follow along to build a complete Symfony 8 + EasyAdmin digital library application from scratch.\n","permalink":"https://naimidevslayer.com/en/cours/developpement-web/symfony-8/mini-bibliotheque/12-required-file-fields-custom-css/","summary":"\u003cp\u003eLast chapter ended with a challenge: our file and image fields are \u003cstrong\u003erequired\u003c/strong\u003e, so when you edit a book, EasyAdmin complains they\u0026rsquo;re empty, even though the files exist. This is a classic EasyAdmin gotcha. Let\u0026rsquo;s fix it properly, then clean up the admin\u0026rsquo;s styling with a custom CSS file.\u003c/p\u003e\n\u003cdiv style=\"position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;\"\u003e\n      \u003ciframe allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen\" loading=\"eager\" referrerpolicy=\"strict-origin-when-cross-origin\" src=\"https://www.youtube.com/embed/GMD-6r8Un38?autoplay=0\u0026amp;controls=1\u0026amp;end=0\u0026amp;loop=0\u0026amp;mute=0\u0026amp;start=0\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" title=\"YouTube video\"\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\n\u003caside class=\"box box-objectives\" aria-label=\"What you\u0026#39;ll learn\"\u003e\n  \u003cp class=\"box-title\"\u003eWhat you\u0026#39;ll learn\u003c/p\u003e","title":"Mini Library Course #12: Fix Required File Fields in EasyAdmin \u0026 Add Custom CSS"}]