Z
Z
zagamay_ru2018-04-12 11:36:07
Laravel
zagamay_ru, 2018-04-12 11:36:07

Why does DI Laravel not work in exactly one controller?

Good afternoon colleagues!
There were difficulties with laravel, DI works fine in it and I use it with pleasure, but creating another resource controller for the admin panel, I cannot write like this:

/**
     * Display the specified resource.
     *
     * @param Keywords $keywords
     * @return \Illuminate\Http\Response
     */
    public function show(Keywords $keywords)
    {
        dd($keywords);
    }

I just get an empty model, instead of Keywords::findOrFail($id).
The show method takes $id and laravel should automatically recognize my model and put this id into it, it works in other controllers, but it doesn’t work in this one ..
I tried to clear the entire cache, rename the model and controller).
And I tried to substitute this model in another controller and everything turned out fine.
in routing like this:
Route::resource('/keywords', 'KeywordsController');
Route::resource('/category', 'CategoryController');

Help me understand why DI does not work in this controller

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
JhaoDa, 2018-04-12
@zagamay_ru

Have you read -  https://laravel.com/docs/5.5/routing#route-model-b... ?

O
okols90, 2019-12-18
@okols90

Run this command php artisan route:list to find the desired controller. And here you need to look at the name of the variable in /keywords/{??????} and replace $keywords with what is here {??????}.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question