Since the .env file is not under version control, it often happens that developers are missing new values, added by other developers, when they pull the latest version. Also the .env.example is often totally out of date, because the team forgot to add new values to it. That's a pain, when a new developer joins the team and tries to set up the project. Laravel offers a default to all env function calls, but thats often not enough. Sometimes you really want to make sure a env variable exists and the developer explicitly defines a value for it. Often .env files get shared around, sent via email or something like that. But this is not really a generic and solid solution. Best would be, if the .env.example would just stay up to date! Let's try to configure some githooks to ensure our .env and .env.example will never ever be outdated anymore!
To compare .env and .env.example files, we'll use a github package called envy, a great package developed by the awesome guys from worksome!
composer require worksome/envy --dev
php artisan envy:install
Now make sure .env and .env.example are listed in the environment_files variable in the config/envy.php
'environment_files' => [
base_path('.env.example'),
base_path('.env'),
],
We need to add some git hooks to our repository. But since the whole .git directory (which contains the default git hooks directory used by git) is also not under version control, we need to create a new directory, which we can add to git, cause for sure we want to share our hooks with the whole team!
cd myproject; mkdir .githooks
The idea is to tell git to compare the both env files before one tries to commit and also after somebody pulls new changes. That means we need to add two git hooks, the pre-commit and the post-merge hooks. So if one tries to commit and forgot to add a new env variable to .env.example an error occurs and also after somebody pulls, and a new variable was merged to .env.example the developer gets notified that he/she should add this variable to his/her .env file.
touch .githooks/pre-commit; touch .githooks/post-merge
Since we use the same script in the pre-commit and post-merge hook, we add a new folder .githooks/scripts and put there the script which we then call inside both hooks (make sure to make them all executable with chmod +x).
mkdir .githooks/scripts; touch .githooks/scripts/envy-check
Now paste the following code to your envy-check script
Call the envy-check script inside your pre-commit and post-merge hooks (make sure your hooks and the envy-check scripts are executable).
nano .githooks/pre-commit
nano .githooks/post-merge
Paste the following content:
-----------
#!/bin/bash
./.githooks/scripts/envy-check
There is one problem left... Just adding a .githooks directory and add there, some script does not tell git to use these. Therefore we create a .gitconfig file and add the following lines:
cd myproject; nano .gitconfig
-------
[core]
hooksPath = .githooks
Now to make sure that git is using our defined .gitconfig we need to make some configuration. For this purpose there is noting better than a good old makefile. Just append these lines to your existing makefile or create a new one:
nano Makefile
-------
enable-git-hooks:
git config --local include.path ../.gitconfignano .githooks/pre-commit
^
make sure to use a real tab indent here - important!
The make package should be on quite every linux-based OS, but if it's not installed on your system, go ahead and install it with sudo apt-get install make.
Now the only thing you need to do is tell your team and new joining developers to run this one-time command: cd myproject; make enable-git-hooks
Basically all default env vars which are maybe not predefined in the default .env file are getting excluded. Just check the exclusions array in the config/envy.php. If you for some reason also want to exclude some env vars, just list em here. Also notice, that envy as default only checks env vars in config/*.php, which is the best practice location to put your env vars. Actually you should not use env vars directly in the code, cause of caching issues.
Now lets asume you worked on a new feature which introduces a new env variable called FOO which is used in some of your config files. You finally finished the feature and want to commit, but forgot to add the env varbiable to .env.example. You type git commit -am "New Feature" and greate you cant commit and you get notified that some vars need to be added to .env.example:
Also in reverse, if now a other team members pulls the lates code (he will not have the FOO env variable set), he gets notified, that there is a new env variable and he/she should define it in the .env.
The rich text element allows you to create and format headings, paragraphs, blockquotes, images, and video all in one place instead of having to add and format them individually. Just double-click and easily create content.
A rich text element can be used with static or dynamic content. For static content, just drop it into any page and begin editing. For dynamic content, add a rich text field to any collection and then connect a rich text element to that field in the settings panel. Voila!
Headings, paragraphs, blockquotes, figures, images, and figure captions can all be styled after a class is added to the rich text element using the "When inside of" nested selector system.
test123
<span style="color:red;">asdfasdf</span>
composer require spatie/laravel-artisan-dispatchable