How to pass two functions in the same route in Laravel 8?

Published

i have this route:

web.php:

Route::get('main',[HomePageController::class,'show']);

that pass this function:

HomePageController.php

class HomePageController extends Controller
{
    function show()
    {
        $data = Classes::all();
        return view('index',['classes'=>$data]);
    }
}

and i want to pass another function in the same route but i keep getting "Undefined variable"
whenever i try to do this:

web.php

Route::get('main',[HomePageController::class,'show']);
Route::get('main',[HomePageController::class,'showfeeds']);

HomePageController.php

class HomePageController extends Controller
{
    function show()
    {
        $data = Classes::all();
        return view('index',['classes'=>$data]);
    }

    function showfeeds()
    {
        $data = Feeds::all();
        return view('index',['feeds'=>$data]);
    }
}

what am i doing wrong here?

Source: Laravel

Published
Categorised as controller, function, laravel, model, php Tagged , , , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq