Documentation in Laravel 8 with Enlighten

The importance of software documentation, even in an agile world, is undisputed. Keeping documentation, especially for APIs, up-to-date however can be an additional burden on a development team, and thus automatically generated documentation can help supplement this by producing reference materials. This is where Enlighten comes in.

In this guide, we’ll get Laravel Enlighten up and running, which utilises your existing PHPUnit tests (because you should be writing tests) to produce and publish beautiful, customisable documentation, without needing to run any additional commands.

System Requirements

Enlighten does require both PHP 7.4 and Laravel 8. I don’t know whether it works with Lumen. 

If you’re running anything earlier, such as Laravel 6 LTS, I would instead recommend Scribe. For other frameworks or vanilla PHP applications, try phpDocumentor.

You will also need a secondary database. It does not need to be a different kind of database, but it does need to be persistent.

You also need an up-to-date version of Git. This is unlikely to be a problem on macOS, Linux or Windows Subsystem for Linux, but it gave me some teething problems directly running on Windows 10 under Laragon.

Please also note that these are as simple installation instructions as possible. For troubleshooting and optional installation steps, please check the project’s repository.

Installation

Composer installation

Do not use sudo for any of these commands. That will open a whole Pandora’s box you don’t want to deal with.

Using Composer, require Enlighten into your Laravel project using the following command. If you somehow don’t have it, grab it here.

composer require styde/enlighten --dev

Registering the service provider

Next, add the following to your config/app.php file to register Enlighten’s service provider. If you’re not sure where this needs to go, put it underneath the package service providers comment, like thus:

[
  'providers' => [
    // ...
    /*
     * Package Service Providers...
     */
     Styde\Enlighten\Providers\EnlightenServiceProvider::class,
    // ...
  ]
];

Important: Be sure to end the line in a comma, not a semicolon.

Publish assets to the public directory

Run the following command to publish Enlighten’s assets to your public directory. Without this, any documents you generate will lack any CSS formatting or JavaScript.

php artisan vendor:publish --tag=enlighten-build

Integrating Enlighten into your tests

In order for Enlighten to activate during testing and to have access to test data, it will need to be imported and initialised during the setup phase of your tests. You can do this in your TestCase.php abstract class, or in individual test files.

For example:

<?php

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Styde\Enlighten\Tests\EnlightenSetup; // import this trait

abstract class TestCase extends BaseTestCase
{
  use CreatesApplication;
  use EnlightenSetup; // and use said trait here

  protected function setUp(): void
  {
    parent::setUp();

    $this->setUpEnlighten(); // the final piece of the puzzle
  }
}

Important: I believe you need to still call parent::setUp() in your setUp() methods within your tests.

Setting up the secondary database

As aforementioned, Enlighten needs another database to record information. The easiest way to do this is to create another database with the same name of your existing one, except with an _enlighten suffix.

For example, if you have used a MySQL database named laravel, you can create another one called laravel_enlighten which will be used automatically. This assumes you’re using the same database connection, credentials, and driver.

Once you’ve made it, run your migrations to get it set up:

php artisan migrate

Optional: Custom database setup

If you need to use something else, add a new entry to your config/database.php file with the name enlighten. This can support a different driver, credentials, database name, etc. You can add this information as custom entries in your .env file – possibly with an _ENLIGHTEN suffix for clarity.

For example:

'enlighten' => [
  'driver' => 'mysql',
  'host' => env('DB_HOST_ENLIGHTEN', '127.0.0.1')
  'port' => env('DB_PORT_ENLIGHTEN', '3306')
  'database' => env('DB_DATABASE_ENLIGHTEN', 'laravel_enlighten')
  'username' => env('DB_USERNAME_ENLIGHTEN', 'root')
  'password' => env('DB_PASSWORD_ENLIGHTEN', '')
// …
],

I think that you could use an SQLite database in theory, but I haven’t tested this and generally stick to the defaults.

Don’t forget to run your migrations if you choose this route.

Running Enlighten

Once you’ve set everything up, Enlighten will run when you run your test suite:

php artisan test

You can then find your new documentation at the yourwebsite.test/enlighten/ URL.

What’s next?

This guide was designed to get Enlighten up and running as easily as possible. More customisation and configuration options are available to make your documentation as detailed and organised as possible. You can read more on the project’s repository.

I hope that you’ve found this guide useful and I encourage you to check it out with your Laravel API projects! It goes without saying, but Enlighten wasn’t written by me – it’s an open-source project headed by Duilio Palacios and Jeff Ochoa.

Thank you so much for reading.

Tips for being a better listener from a former helpline volunteer

The Internet has a wealth of great articles with a wealth of useful advice on supporting your fellow developers, colleagues, and most critically, yourself, as you progress through your software engineering career, or whatever path you find yourself upon. This really motivated me to write my own post on this topic, one of which is close to my heart.

For a bit of background, whilst at university, I became interested in volunteering and mental health. In British, Irish, and other European universities, many students volunteer for a local Nightline – a listening service staffed by fellow students who volunteer their time supporting the wellbeing of others in their respective communities by providing a listening ear and a source of empathy when often most other services are unavailable. As a volunteer with my university’s branch, I’ve since contributed well over 1100 hours to peer support, and an additional 200 in training other volunteers – so I’ve certainly learned a thing or two!

With that in mind, here are 5 tips on being a better listener, and how you can better support others! This is a long article, I apologise, but I promise that you will learn something from it!

Please note: This is not advice or guidance on how to support someone in a crisis. Please consult a mental health first aider at your organisation, or immediate medical assistance in an emergency.

1) Make better use of Active Listening

Active Listening is the act of conscientiously listening to someone, providing feedback, and giving someone space to talk freely without judgement or advice. Three key techniques encompass this:

Summarising

Repeating back something that someone said to you to demonstrate that you are listening to them. This can take the form of literally echoing back what they’ve said:

“I’m having real trouble understanding linear search algorithms.”
“Trouble understanding linear search algorithms?”

Or can be in the form of a summarisation – summarising what they have said to you – providing an opportunity to ask a question and be empathetic.

“Thanks for telling me about what you’re going through with your new colleagues, in particular with the name-calling. Can you tell me anything more about them?”

(Open) Questioning

Again like with the example above, asking open (so questions that cannot be responded with merely yes or no) questions to encourage someone to talk.

“How is it making you feel?” “Have you spoken about this with anyone else?” “What actions have you considered?”

Encouragement

Use affirmative noises, noises like “mhm” and if the conversation is face-to-face, actions such as nodding and maintaining eye contact can help let someone know that you care and that you are listening. Don’t keep checking your phone! If someone needs more time to talk or find their words, remind them that they can take all the time they need. Remind them that you won’t judge them.

2) Don’t immediately look to problem solve

If you’re talking with someone and they ask for your advice, or for guidance on what they should do, it’s a good idea rather than to attempt to solve their problems for them, to give them an environment in which they can come to their own answer independently. You can help guide them to potential outcomes without giving your own opinion.

What do I mean by this in action? Let’s role-play.

Colleague:

I’m having trouble keeping up with my workload and it’s causing me a great deal of stress. Honestly I don’t know what I should do.

You – good answer:

I’m sorry to hear that you’re feeling stressed. Would you like to talk to me more about what’s on your workload?

You – poor answer:

You should probably talk to your supervisor about that; there’s not really much I can do to help you there.

As you can see, the first answer is empathetic and offers an opportunity to talk about the problem more. The second answer breaks interpersonal rapport and will often make the other person not want to talk about what they’re going through since you’ve already provided a solution. Chances are – they’ve already considered that anyway.

Furthermore, there might be further underlying reasons for them wanting to talk. They have initially mentioned workload, but by probing further into their situation, there may be other underlying causes, perhaps a bereavement, illness, etc. that might be contributing to the difficulty keeping up with their workload.

3) Use their language

Of course, I don’t mean a language itself (like French), but rather what words and terminology someone uses, you should mimic naturally when you speak to them.

Believe it or not, we tend to do this subconsciously anyway (code-switching) but making an active effort to live in their world and use the terminology that they use can help you build a rapport with someone and to let them know that you are attentively listening to them. This also helps you avoid making any assumptions, as you’re only using words that they have given you.

For example, if someone wants to talk to you about a problem they’re having with their partner, then use that word. Don’t substitute it with boyfriend, girlfriend, wife, husband, whatever, and vice versa. It should go without saying, but this extends to people’s preferred pronouns also.

Exceptions apply. You don’t need to use phrases or words you feel uncomfortable with, or that are derogatory. If in doubt, ask.

4) Avoid using the word ‘why’

The term why can sometimes feel judgemental or confrontational. Consider the two examples:

With why:

Why do you feel that way?

With an alternative phrasing:

What makes you feel that way?

It seems simplistic and almost nit-picky, but you will find that many active listening programmes will encourage avoiding the term.

5) Understand the difference between sympathy and empathy

Sometimes we use the terms interchangeably in the English language – but they are different emotions. Empathy is vulnerable and requires a commitment to coming down to someone’s level to experience their emotions and experience as they do. Sympathy, is simply: “that’s too bad.”

The best explanation for this comes in the form of a short animation by Dr Brené Brown. I implore you to give it a watch!

Conclusions

From this article, I hope that you are able to understand a little about Active Listening, how being non-directional and non-judgemental can aid your conversational skills and support others, that your choice of vocabulary can seriously matter, and the dramatic difference between empathy and sympathy.

These skills can be lifesaving and will help you in your everyday job, your interpersonal relationships, and even with your own wellbeing.

Remember these golden words: If in doubt, ask!

Thank you so much for reading.