N
N
NikolayAlb2017-04-18 21:12:58
Laravel
NikolayAlb, 2017-04-18 21:12:58

Laravel 5.4 how to properly inject a dependency into a POST request?

For example, I have a form, it has a user_name field, I would not want to write this in the controller:

public function postDoSomething(Request $request)
{
    //code...
    $user = User::where('name', '=', $request->user_name)->first();
    //code...
}

How can you inject a dependency in such a case that an already found user comes to the request?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Victor, 2017-04-18
@NikolayAlb

Route Model Binding

P
pantagruel964, 2017-04-18
@pantagruel964

There is an example in the doc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question