This was the first ever laravel project made by myself. It only features basic CRUD operations and some basic bootstrap classes for displaying and spacing the records in the database.
- PHP >= 7.4 https://devdojo.com/tnylea/installing-php-on-windows
- composer https://getcomposer.org/
- Mysql server https://www.sqlshack.com/how-to-install-mysql-database-server-8-0-19-on-windows-10/
- Code editor, I personally recommend VSCode because of the extensions
Once the requirements are fullfilled, we can download or clone repository, install the project and run it
- First Download project folder OR clone using git bash https://git-scm.com/downloads
Then we need to change the ".env.example" file name to just ".env" and change de database connection parameters inside of it to your own db user and password if required
- Once downloaded or cloned to your computer, access to project folder with the git bash cli (or cmd, powershell, whatever you use) and run the following commands:
composer install #this will install the packages specified in composer.json file, required by the project
composer update #check for new versions of those packages
php artisan serve #this will launch the laravel development server
now simply navigate to the link provided by the server (localhost:8000/productos) and you should be able to see the project running
To set up our database and create the required columns we don´t have to write any sql statements. Laravel comes with a CLI (command line interface) that helps us build what we need without writting any php code or such.
So, for adding columns to our actual database (which in this case is called carnes but we can change the name on the .env file), first we have to create it, so go ahead and create a new database called "carnes" so that we can run the project right away without modifying any of the actual code just to see it running.
Once the database is created and confirmed that the name on the .env file is the right one, we can go ahead and create the columns for it, which are the attributes we have already defined in class. As I said, laravel gives us a command line interface to interact with laravel and do so many things, called Artisan and executed by PHP.
Go to your terminal and type
php artisan migrateand check the database. If everything went OK, you should now see the columns into the database
Once we have the database ready, we can really test the CRUD operations on the db from laravel. So access localhost:8000/products/create and the form for adding new products to the db should display. Try adding values to it and save it, go to the database and check for that new record.