mercredi 1 juillet 2020

laravel - how can I call a function stored in a controller after saving to a database?

I'm following a tutorial on Laravel, adding to a DB via a form. At the end of a function that saves to a DB, it returns back to the page where the form is, but I want to be taken to another page where the information is displayed. In the tutorial I created a controller with a function that returns a view containing all the database info - that element works fine however I can't seem to find a way of calling this function directly after saving to the database. I can also return any other view which just displays static view ( just html with no data handling ). Is what I'm trying to achieve possible?

  public function store(){        

        $li = new \App\LTest1();
        $li->creator = request('creator');
        $li->title = request('title');
        $li->views = request('views');
        $li->save();
        return back(); // this works
       // return view('info');  // this works
       //return ('Listings@showList');   this doesnt work = how do i call a function in a controller???
    }
// routing

Route::get('info', function () {
    return view('info'); // i can get to this static page from my store() function
});

Route::get('thedataviewpage', 'Listings@showList'); // you can route to this but not from the store() function


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire