Hello,
Im facing some trouble trying to bind some classes dinamically in my Route.
I have the current Routes:
Route::resource('post', 'PostController');
Route::resource('comment', 'CommentController');
everything normal untill here, my problem is:
Route::post('post.like', 'LikeController');
Route::post('comment.like', 'LikeController');
so i can call /posts/1/like and /comment/1/like and use the same controller 'LikeController' in diferents contexts
I want to bind the interface dinamically
App::Bind('LikeableInterface',
.. but need to fill it dinamically from the route to construct the controller.
class LikeController extends BaseControler
{
public function __construct(LikeableInterface $resource
{
[...]
The Likeable can be an Comment or a Post, depending of the route. Anyone know how to achieve this in Laravel?
Thank You.
Sounds to me like you are talking about Traits. I'm currently reading about this new feature to php>=5.4, so i can point you to couple resources, but i can't give you code that will solve your problem.
But in my understanding you can extract that 'like' feature to trait and then you can add that trait to any number of controllers.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community