When laravel tries to serialize an object with closures it throws an exception "Serialization of 'Closure' is not allowed". We need to be able to serialize objects with closures in order to use League Events.
This is a limitation of PHP. Nothing Laravel can do about it.
It can be done: https://github.com/jeremeamia/super_closure
don't mind me, just talking out of my ass.
The problem is not that we have an exception, but that we can't really handle it.
This throws a generic \Exception.

Even something as simple as this would be of help, imho.
I can handle that :)
LE: In my use case, i was trying to do a middleware that caches responses.
This was throwing exceptions in some cases.
i fixed this with the following:
try {
$_response = '';
$response = cache()->remember($token, $ttl, function () use ($request, $next, &$_response) {
$_response = $next($request);
return $_response;
});
} catch (Throwable | Exception $e) {
$response = $_response;
}
return $response;
I hope this is of help to you guys :)
Hi there,
Welcome to Laravel and we are glad to have you as part of the community.
Unfortunately this GitHub area is not for ideas, suggestions etc. This is only for issues/bugs with the framework code itself.
I will be closing your ticket here. You are able to open a ticket at https://github.com/laravel/ideas
Alternatively you are able to open a PR using the Contributions guidelines: https://laravel.com/docs/5.7/contributions#which-branch
If you feel I've closed this issue in error, please provide more information about how this is a framework issue, and I'll reopen the ticket.
Thanks in advance.
You can also work around this by using constructor args in your jobs with static callables. A string or a tuple (of strings).
So long as serialize in Illuminate\Queue\Queue::createObjectPayload doesn't eat it, you should be ok.
Most helpful comment
https://github.com/opis/closure