K
K
Konstantin Malyarov2017-08-10 20:34:57
Laravel
Konstantin Malyarov, 2017-08-10 20:34:57

How to get parameter from url in laravel?

There is a route:

Route::resource('/home/staff_doctor/patient/{patient}/passport', 'PassportController');

There is a link:
<a href="{{route('passport.index', ['id' => $patient->id])}}"
                       class="btn btn-success btn-xs">Добавить паспорт</a>

There is a controller:
public function index($id)
    {
        $patient = Patient::find($id);
        return view(route('passport.index'), compact('patient'));
    }

How to make controller accept value from url?
/home/staff_doctor/patient/ 3 /passport
SOLUTION
Corrected the link:
<a href="{{route('passport.create', ['patient' => $patient->id])}}"
                       class="btn btn-success btn-xs">Добавить паспорт</a>
                    <a href="{{route('passport.index', ['patient' => $patient->id])}}"
                       class="btn btn-primary btn-xs">Посмотреть все</a>

Added a request in the index function in the controller:
public function index(Request $request)
    {
        $patient = Patient::find($request->patient);
        return view(route('passport.index'), compact('patient'));
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
First Last, 2017-08-10
@Konstantin18ko

<a href="{{route('passport.index', ['patient' => $patient->id])}}"
                       class="btn btn-success btn-xs">Добавить паспорт</a>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question