So you have a proxy to the image with some middleware/logic like (Auth::check()) protecting from only allowing logged in users. I would have thought the session/cookie be passed with the request?
I assume you are checking logged in on the PDF generation so you could probably do this and forget the proxy check:
<img src="/var/www/domain/path/to/storage/image.jpg" />
As far as your other question testing access you could determine this I guess by checking the current URI
app('router')->current()->uri();
if something was resolved out of the container from another class you could use debug_backtrace()
$backtrace = debug_backtrace();
if (
isset($backtrace[2]["class"]) &&
isset($backtrace[2]["function"]) &&
$backtrace[2]["class"] == "Illuminate\Routing\Controller" &&
$backtrace[2]["function"] == "callAction"
)
{
// 'usual routing';
}
if (
isset($backtrace[1]["object"]) &&
isset($backtrace[1]["function"]) &&
$backtrace[1]["object"] instanceof FooController &&
$backtrace[1]["function"] == "bar"
)
{
// 'bar method in FooController made the call';
}
Or as backtrace is potentially unreliable, pass a flag in the call and check the param on the method?
$bar = app()->make('App\Http\Controllers\FooController')->bar($internalCall = true);