jeudi 18 février 2021

Where I can place the logic that generate a pdf response on my laravel app?

Ι am maintinaning a legacy laravel 5.2 application and I have the following controller:


namespace App\Controllers

use App\Model\MyModel;
use Illuminate\Http\Request;

class MyController extends Controller
{
  public function myPdf(Request $request)
  {
    $filterVal = $request->get('filter_var');
    $data = MyModel::where('value',$filterVar)->get();

    // Generate a pdf response here
  }
}

But for me from an architectural point of view seems wrong to place any view-generation logic towards to a controller. The controller responds with a PDF response (the http response has Content Type header application/pdf) and having the logic in the controller is wrong because the pdf is the view of my data.

So do you have any idea how I can create custom responses that generate pdf using libraries such as DomPdf?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire