Laravel: load view after publication

In Codeigniter, I used the view function after posting the data. As shown below;

Ex: I have a show_products () function that displays a list of products. When the user adds a new product, I send the data to the add_product () function. If the process is successful, I do not redirect to the product page, instead I load the display function inside add_product () as follows:

//Inside the add_product() function
if(success){

   $this->show_products();

}

I think it makes no sense to reload the page again. Since we are already in the post function, we can immediately set the view after inserting the database.

However, in laravel, I see people being redirected after posting data.

Example:

//Inside the postProduct() function
if(success){

   return Redirect::to('products');

}

I tried;

//Inside the postProduct() function
if(success){

   $this->getIndex();// this is my product display function

}

but it didn’t work.

, post ?

, ?

!

+3
4

Laravel, . , / .

CodeIgniter Php . , , , , /?

:

  • /.
  • , .

. , . - :

return View::make('...')->with('success', 'Data saved!');

success , , f5 refresh (, ), , .

, , refreshing .

Google ., , /, .

+4

Codeigniter redirect().

if(success){
    redirect('products');
}
+1

You do not need to return Redirect. The reason people often use it in larvel is because it is convenient.

You can return something else, for example. view:

return View::make('home.index')->with('var',$var);
+1
source

In Laravel, to redirect after POST, you can return a redirect with a named route:

return redirect()->route('my-route-name');

Or, if you are in a controller that has the route method that you want (for example, a method index, you can also do this:

return self::index();
0
source

All Articles