Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I serve generated phpDocumentor docs from Laravel?

So I'm using phpDocumentor 3 to generate documentation for my Laravel 7 project,

and was wondering if I could serve this documentation (static files) from Laravel in order to make it available only to authorized users.

I would like to be able to update the documentation through my CI/CD, so I can't just modify manually the generated documentation.

I think that I might have to write my own template (https://docs.phpdoc.org/3.0/guide/guides/templates.html) for that but I'm not sure whether the documentation is incomplete or if I'm missing something because I have no idea how to create a template. Any suggestions, guides or tutorials that can help me achieve this please ?
Thank you

like image 390
hereForLearing Avatar asked Nov 07 '22 00:11

hereForLearing


1 Answers

You can include the phpDoc generation within your CI/CD script:

first install the phpDocumentor on the production, then generate using this command:

phpDocumentor -d . -t storage/docs/ 

Note: the storage path maybe is gitIgnored if you plan to generate the phpDocs, not on the production server, you have to be sure that the folder will be pushed to the production

add this to the config/filesystem.php 'disks':

'local-docs' => [
            'driver' => 'local',
            'root' => storage_path('docs'),
        ],

and add the following in your routes file (routes/web.php)

Route::get('/docs/{url?}', function ($url) {
    $resp = response(Storage::disk('local-docs')->get($url));
    $resp->header('content-type', GuzzleHttp\Psr7\MimeType::fromFilename($url));
    return $resp;

})->where('url', '(.*)')->middleware('auth');

be sure you haven't any other route with the docs prefix

like image 169
Abilogos Avatar answered Nov 14 '22 03:11

Abilogos