W
W
WebDev2016-05-17 10:52:25
Laravel
WebDev, 2016-05-17 10:52:25

Laravel model binding?

Tell me, when binding a model, the variable that I accept in the model should be called the same as in the route?
I.e:

Route::get('entity/{id}', '[email protected]');

class EntityController {
    public function edit(Entity $id)
    {
        //code
    }
}

In the example above, in the edit method, should I name the variable exactly $id? Does it not work with another name or am I doing something wrong? In the docks everywhere, the name of the variable is the same as the name in the route and it turns out not very logically:
$id->remove();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Pochepko, 2016-05-17
@kirill-93

No. Model binding is when in your routes you have a BlogModel model under a certain {my_model} line.

// Provider
$toute->bind('my_model', Blog::class);

// Route
Route::get('entity/{my_model}', '[email protected]');

// Controller
class EntityController {
    public function edit(Blog $model)
    {
        //code
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question