mardi 9 février 2021

How to add a piece of code for a package in bootstrap/app.php file and its implication in the performance of laravel app

In my project, I am trying to use thephpleague/glide for URL based image manipulation which works absolutely fine with the codes mentioned below.

But the problem is that I am unable to figure out how this piece of code is going to affect the performance of my project as I have never added a single line of code in bootstrap/app.php file before. I want to know how this piece of code is going to affect my app's performance and is this the right way to do it or is there any better way.

I will be highly thankful if anyone suggests any other or better way to add this piece of code in config or anywhere else.

Code update in bootstrap/app.php

$app->singleton('League\Glide\Server', function ($app) {

  $filesystem = $app->make('Illuminate\Contracts\Filesystem\Filesystem');
  return \League\Glide\ServerFactory::create([
    'source'                => Storage::disk('s3')->getDriver(),
    'cache'                 => Storage::disk('local')->getDriver(),
    //'source_path_prefix'    => '',
    'cache_path_prefix'     => 'uploads/images/.cache',
    'base_url'              => 'img',
    'useSecureURLs'         => false,
  ]);
});

Route

Route::get('img/{path}', function (League\Glide\Server $server, 
    Illuminate\Http\Request $request, $path) {
    $server->outputImage($path, $request->all());
})->where('path', '.*');

In the original code which I found on the GitHub it was mentioned to use this code in config instead of bootstrap/app.php, but I have no idea how to do it.

Any kind of help or any alternate and better suggestion is highly appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire