S
S
Sergey Kotov2020-01-27 11:54:02
Laravel
Sergey Kotov, 2020-01-27 11:54:02

How to pass template names through laravel route?

Route::get('equipment', '[email protected]');
Route::get('/', '[email protected]');

public function allitems(){
        return view('здесь нужно передать название шаблона', 
            [
                'all' => $this->eqs(),
                'types' => $this->types()
            ]);
    }


You need to pass the name of the view to the allitems method

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kim, 2020-01-27
@liqrizz

Route::get('/', '[email protected]');
Route::get('equipment', '[email protected]');

private function allItemsInternal(string $template){
    return view($template, [
        'all' => $this->eqs(),
        'types' => $this->types()
    ]);
}

public function allItems(){
    return $this->allItemsInternal('all');
}

public function allEquipmentItems(){
    return $this->allItemsInternal('equipment');
}

A
Antonio Solo, 2020-01-27
@solotony

in the controller find out the route Route::currentRouteName();
and knowing the route, choose a template

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question