I think you just need to tell guzzle to use cookies so it can track the session cookie.
$client = new Client(['cookies' => true]);
// then send a post request to LOGIN with your credentials.
$client->post('/login', [
'form_params' => [
'username' => '[email protected]',
'password' => 'yourPassword',
],
]);
// then send your get request once authenticated
$html = $client->request('GET', $pdfPrintUrlContent)->getBody();
// then logout
$client->get('/logout');
No, because it's based on the cookie, which is what laravel's auth is checking for so it needs to be present. No session cookie, no auth. So you just need to simulate what the browser is doing when you log in, and use cookies.
You could set up an api with laravel passport and use tokens and pass the token in the request, but that's overkill for this.
So... where exactly is Guzzled called from? I need more context.
If you're on PageA and trying to get HTML from the PageB, just execute the controller action that's loading PageB, or hardcode View that PageB controller is rendering.
If this is within one app, I am pretty sure Guzzle is not right way to do this. You have full control over your code and what is rendered where, yet you call Guzzle to make trip to your own server?
That would have been better to start with lol. So just do as @crnkovic said and load the view file and just render it. Then use the rendered html how you want. You don't need guzzle for this at all.
$view = view('my-template');
$html = $view->render();
// now use $html for your pdf
You can send variables to the view if needed like normal.