-
-
Save gabbydgab/df35f753586cd1d3d1374b5d5aeed5a4 to your computer and use it in GitHub Desktop.
<?php | |
/** | |
* Following binding works! | |
*/ | |
namespace MyPackage\Model; | |
class User | |
{ | |
} | |
namespace App\Http\Controller; | |
class UserController | |
{ | |
public function view(User $user) | |
{ | |
dd($user); | |
} | |
} | |
// routes/web.php under App\Http\Controller | |
Route::get(/user/{user}, "UserController@view"); | |
/** | |
* Following binding doesn't works! | |
*/ | |
namespace MyPackage\Model; | |
class User | |
{ | |
} | |
class UserController | |
{ | |
public function view(User $user) | |
{ | |
dd($user); // is null | |
} | |
} | |
// routes/web.php under MyPackage\Http\Controller | |
Route::get(/user/{user}, "UserController@view"); | |
@gabbydgab thanks!
@gabbydgab thanks
Hey Guys just wondering what your solutions looked like for this. Bit confused on what I need to include and where to write it. When trying to include a wrap i get a RuntimeException: No application encryption key has been specified. Which is strange in my package cause Ive never seen a package with a .env @SadeghPM @monurakkaya
Hey Guys just wondering what your solutions looked like for this. Bit confused on what I need to include and where to write it. When trying to include a wrap i get a RuntimeException: No application encryption key has been specified. Which is strange in my package cause Ive never seen a package with a .env @SadeghPM @monurakkaya
@James-N-M
just runphp artisan key:generate
@monurakkaya I refereed to your https://github.com/monurakkaya/laravel-image src/app/Providers/ServiceProvider.php file and saw the example of the usage that @gabbydgab recommended. Route Model Binding is now working thank you ! ❤️
Add the following to your Service Provider files boot method.
// top of file
use Illuminate\Support\Facades\Route;
// inside boot method
Route::group([
'middleware' => ['bindings'],
], function () {
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
});
thank you a lot by clarify the solution.
you solved one of my biggest challenges in making a package in the last few days.
Add the following to your Service Provider files boot method.
// top of file use Illuminate\Support\Facades\Route;
// inside boot method Route::group([ 'middleware' => ['bindings'], ], function () { $this->loadRoutesFrom(__DIR__.'/../routes/web.php'); });
solution: include 'bindings (SubstituteBindings)' middleware
Route::group([
'middleware' => ['bindings'],
'prefix' => $prefix,
'namespace' => $namespace
], function () {
$this->loadRoutesFrom(DIR . '/../../routes/api.php');
});