The open source software development course's repository.
It lies on the same basis as Mars to prepare its development.
For OS X, Valet gives a pretty smooth experience. Easy to download, easy to configure.
For Windows and Linux we will use Laravel Homestead for local development. With Homestead, the web server is hosted from a virtual machine with the help of VirtualBox and Vagrant.
-
If you haven't already, download and install Git, GitHub Desktop, VirtualBox, and Vagrant.
-
Recommended: create a new folder named "Git" for your git projects.
-
Fork (click on the fork button at top right corner of the page) and clone (~Download) your fork of the Pluto repository. You can easily do this with
Github Desktop. If you can not find this option there, clicking on the greenCodebutton on the GitHub webpage and selectingOpen with GitHub Desktopwill do the job. Or you can use the command line too to clone the directory (see point 5.). Make sure to clone theyour_username/pluto, not theEotvosCollegium/plutorepository. -
Open a terminal and navigate to your git folder. (If you are not familiar with the command line, watch some YouTube tutorial about the terminal basics.)
-
Run
git clone https://github.com/laravel/homestead.gitto clone Homestead. This will create a folder named Homestead in your git folder. We will refer this as your "Homestead directory". -
Navigate to your Homestead directory:
cd Homestead. -
Run
bash init.shon macOs/Linux orinit.baton Windows to create theHomestead.yamlconfiguration file. -
The only essential thing to set in this file is to set the path to your project. For example:
folders:
- map: C:\Users\domi\Documents\GitHub\pluto
to: /home/vagrant/code
The above line will map the folder C:\Users\domi\Documents\GitHub\pluto to the folder /home/vagrant/code in your Homestead virtal machine.
-
You will need to create ssh keys to connect to the Homestead VM. Run
ssh-keygen -t rsa -b 4096 -C "[email protected]"to generate the keys (if the system can not find this command, try running it inGit Bash- this program should have been installed with git.) If the prompt saysEnter file in which to save the key...just press enter to create the file in the default location, then enter a passphrase (~password, but we won't need to remember it). -
In your Homestead directory, run
vagrant up. This will create a virtual machine with the Homestead configuration. If no error messages appear, runvagrant sshto connect to the virtual machine. You will find yourself in the/home/vagrantdirectory in the VM. Here everything is installed and set up for you, including php, mysql, composer, etc. -
Navigate to your project folder (
cd code). We will be working from here from now on. -
Run
composer installto install the laravel dependencies. -
Run
cp .env.example .envto copy/create the.envfile. This is the file that contains the environment variables, therefore it is not synced with git. You can add your own passwords and other sensitive information to this file. Fill in theDEVELOPER_NAMEandDEVELOPER_EMAILvariables to use your custom login credentials. -
Run
php artisan key:generateto generate the application key in.env. This is used for security purposes. -
Run
php artisan migrate:fresh --seed. This will create the database tables (migrating) and fill them with the default data (seeding).freshindicates to drop the existing tables first, if you had some - this will be useful later. -
Now you should be able to access the website by entering
192.168.10.10in your browser. Log in with[email protected](or your custom email set in.env) andasdasdasdas password. -
Congrats, you can start coding! You changes will be synced automatically and you can test it in the browser.
Notes:
- As you can see, Laravel's commands are look like
php artisan ~:~ --options. Get used to it. To create a new file, it is recommended to usephp artisan make:model ModelNamefor example (also: controller, migration, etc.) - For more configuartion options (eg. use custom website names instead of
192.168.10.10), look at the Homestead documentation. - To shut down the Homestead VM, run
vagrant halt. - Most of the above setup is a one-time thing to do. However, whenever you start working, you might need to run
vagrant upandvagrant sshto start the virtual machine. If you create migrations or you want to reset the database, runphp artisan migrate:fresh --seed.
The basic things you will need as a beginner:
- Controllers:
app/Http/Controllers- the main functionalities of the backend - Database:
- Migrations:
database/migrations- the database structure can be modified with migrations - Seeders:
database/seeders,database/factories- the database can be seeded with dummy data which are set in factories - Read the documentation of queries to understand how to insert/update/delete data in the database. Laravel also has particular functions for inserting and updating models. The queries will mostly return Collections, which are similar to arrays but with custom functions.
- Migrations:
- Models:
app/Models- the database is mapped to php classes using Models (ORM - Object Relational Mapping). Models are the main way to interact with the database. To create Models, usephp artisan make:model ModelName -ato generate the model and a corresponding controller, factory, etc. Also take a look at Relationships to define relations between Models. - Routes:
routes/web- to map the requests from the browser to controller functions - Frontend:
resources/views- the webpage is generated from these blade files. To return a webpage, usereturn view('path.to.view', ['additional_data' => $data, ...]);. Blade files are html codes with additional php functionalities: loops, variables, etc. Writing{{ something }}is equivalent to php's print:echo something;. When writing forms, add@csrfto the form for security reasons (without it, the request will not work). Blade files can also be nested, included, etc (eg.@include('path.to.file'))). Our front-end framework is Materialize. - Language files:
resources/lang- to translate the webpage. Use__('filename.key')in the backend and@lang('filename.key')in blades. To add variables:__('filename.key', ['variable' => 'value']), prefix the variable name with:in the language files. - Validation: It is recommended to validate every user input: for example, in the controller:
$request->validate(['title' => 'required|string|max:255']);. Available validation rules. - Debugging: log files:
storage/logs/laravel.log- useLog::info('something happened', ['additional_data' => $data])to log (also: error, warning, etc.). Alternatively, in the controllers, you can typereturn response()->json(...);to print some thing in the browser. In blades, type{{ var_dump($data) }}to display some data. It is worth to take a look at the query debugging options also.
You can use php artisan db command to enter into the database directly or php artisan tinker to get a runtime laravel evaluation tool.