0
controller
namespace App\Http\Controllers\Pdf;

use App\Models\PDF;
use App\Models\TestMcq;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class TestPdfController extends Controller
{
    public function createPDF($id) {
        $TestMcq = TestMcq::where('test_id', $id)->get();
        $data = [
            'title' => 'Welcome to ItSolutionStuff.com',
            'date' => date('m/d/Y')
        ];
        $pdf = PDF::loadView('pdf.test', $data);
        return $pdf->download('test.pdf');
      }
}
web.php
Route::get('/test/pdf/{id}', [TestPdfController::class, 'createPDF']);
'providers' => ServiceProvider::defaultProviders()->merge([
        Mccarlosen\LaravelMpdf\LaravelMpdfServiceProvider::class,

        /*
         * Package Service Providers...
         */

        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        // App\Providers\BroadcastServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,

        Yajra\DataTables\DataTablesServiceProvider::class,
    ])->toArray(),

    /*
    |--------------------------------------------------------------------------
    | Class Aliases
    |--------------------------------------------------------------------------
    |
    | This array of class aliases will be registered when this application
    | is started. However, feel free to register as many as you wish as
    | the aliases are "lazy" loaded so they don't hinder performance.
    |
    */

    'aliases' => Facade::defaultAliases()->merge([
        // 'Example' => App\Facades\Example::class,
        'PDF' => Mccarlosen\LaravelMpdf\Facades\LaravelMpdf::class,
        'DataTables' => Yajra\DataTables\Facades\DataTables::class,
    ])->toArray(),

I didn't know why gives me an error ?

...............................................................................................

I don't know why it gives me this error. I tried to deal with it a lot, but it gives me this strange error. I made another file and put exactly the same things in it and it worked, but I need to add it to this project

1
  • you defined the PDF facade as model 'use App\Models\PDF' instead of facade Commented Jun 16, 2023 at 2:54

1 Answer 1

0

PDF doesn't exist in app/Models folder. Try this:

use App\Models\PDF; // replace this with "use PDF" (for calling via alias) OR "use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf as PDF" (for direct calling)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.