Repository navigation
Setup
These instructions will help setup the development environment using docker. It is also possible to run without docker, however no instructions are provided for that.
The following items are required when using these instructions.
- Docker (when using Windows make sure you're able to use Hyper-V)
The following items are recommended to make your life easier.
- PHPStorm to make use of pre-configured Xdebug
- PHP >= 7.1 installed
- Composer (http://getcomposer.org)
- NodeJS (https://nodejs.org)
- Yarn (https://yarnpkg.com)
For convenience sake the PHP container is able to run composer and yarn commands. However, it is often easier to run them outside of Docker.
First clone the repository (or use the HTTPS clone version)
git clone git@github.com:HuInstituteForICT/workplacelearning.git
Enter the project folder
cd workplacelearning
Copy the .env.example to .env. It is not yet necessary to configure the values inside.
Install the PHP dependencies. This can be done through the PHP container, or if you have Composer installed locally through there.
# First build the container as it does not exist yet, can take a while, grab a coffee.
docker-compose build --no-cache php && docker-compose run php composer install
or
composer install
Now start the other containers with
docker-compose up -d
Create the database schema by running the migrations with
docker-compose run php php artisan migrate:refresh --seed
Updating the database later on can be done by simply running
docker-compose run php php artisan migrate
Install should be finished
You can now reach the following services:
| Service | Location |
|---|---|
| Webserver | localhost |
| DB client | localhost:3306 |
| PhpMyAdmin | localhost:8080 |
| Mailcatcher | localhost:1080 |
Javascript and CSS should be compiled before first use and after every asset update. This can be done using Laravel Mix.
This requires that the NPM modules are installed, install them with:
docker exec -it wpl_php npm install
Or if NPM is available on host machine use npm install
Now you can compile assets with
docker exec -it wpl_php npm run dev
To keep compiling on changes
docker exec -it wpl_php npm run watch
Translations can be added and modified manually by editing the right lang files in resources/lang/*.
Another approach is to use the Laravel Translation Manager package, available in dev environment at localhost/translations.
Instructions on how to use it can be found at its github page.
React/JS translations are stored in resources/lang/*/react.php. These are compiled to the public/messages.js file with php artisan lang:js.
So don't forget to compile whenever you add new translations that are used in React/JS.
Laravel has three ways to use translations:
- Lang::get('namespace.key')
- trans('namespace.key')
- __('namespace.key') or __('string to translate')
with the latter using .json files first. Recommended is to only use the __('') function as it will check both json and normal translations files, removing the need to decide which helper to use.
It is possible to use Xdebug with docker and PHPStorm, follow the steps below to configure it correctly.
Open the preferences (Mac: command + , , Windows ctrl + s) and navigate to languages & frameworks > php > servers
Now create a new server with:
- Name: wpl
- Host: localhost
- Port: 80
- Use path mappings: enabled
- Mapping: project root -> /var/www/
Now go to Language & Frameworks > PHP > Debug, in the Xdebug settings set:
- Debug port: 9000
- Enable all 3 checkboxes
Xdebug should now be ready to use, try it by setting a breakpoint in the code and opening a page that executes that code.
Tests can be ran in the IDE by configuring PHPUnit in it.
Alternatively you can execute it in the PHP container by running:
docker-compose run php php ./vendor/bin/phpunit