PHP code example of codezero / laravel-route-key-exists
1. Go to this page and download the library: Download codezero/laravel-route-key-exists library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
codezero / laravel-route-key-exists example snippets
public function getRouteKeyName()
{
return 'id';
}
public function getRouteKey()
{
// "encode" the route key
return "foo-{$this->id}";
}
public function resolveRouteBinding($value)
{
// "decode" the route key
$id = (int) str_replace('foo-', '', $value);
// resolve from the database
return $this->where('id', $id)->first();
}