Skip to content

Instantly share code, notes, and snippets.

@DarkGhostHunter
Last active November 11, 2022 05:26
Show Gist options
  • Save DarkGhostHunter/383abdf8615b40f1041913dd45d2958b to your computer and use it in GitHub Desktop.
Save DarkGhostHunter/383abdf8615b40f1041913dd45d2958b to your computer and use it in GitHub Desktop.
An invokable class for route binding
<?php
namespace App\Http\Bindings;
class Transport
{
/**
* Resolve the route bind
*
* @param string $value
* @param \Illuminate\Routing\Route $route
* @return \App\Transports\TransportContract
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function bind(string $value, Route $route)
{
try {
return app(TransportManager::class)->driver($transport);
} catch (\InvalidArgumentException $exception) {
abort(404);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment