Created
September 2, 2017 13:12
-
-
Save gabbydgab/df35f753586cd1d3d1374b5d5aeed5a4 to your computer and use it in GitHub Desktop.
Route Model Binding in Laravel Package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you a lot by clarify the solution.
you solved one of my biggest challenges in making a package in the last few days.