Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vinschi's avatar
Level 16

Refresh a view after inserting a new instance of a model

Hi guys, I have one question for you: is there a way to refresh a view after I saved an instance passed to the view?

Imagine you have this scenario: you have an index page, you click on edit for one element and after you hit the edit/update methods you redirect back to the index page. Is there a way to have in the index page the list of elements included the last updated one? Thanks

0 likes
3 replies
Jman's avatar

I don't understand the question sorry, not sure it that's why no one else has answered. It seems like it should be there if you have updated one and are refreshing the page... surely you are retrieving the full list on reload?

MilitaruC's avatar

You can use ajax on front page to reload what you consider to be refreshed.

peacengara's avatar

Yes it's possible my friend, I hear your question and I hear it fully ..

2 Possible ways you can do that .. so you need to capture old data ..

In Programming we call it old caching or session management .

** First Approach (probably the easiest) Save Data to Log File with index keys and reload on index refresh.

** Second Approach Save Data to session

     request()->session()->push('custom_refresher', [
    'id', => 'random_id',
     'name' => 'whatever'
     ]);

** If you are in the view you call the request facade or global helper

    request()->session()->get('custom_refresher');

There you go your data is there ..

With that in mind after redirecting back, you then set values from controller to say number of redirect back is this ..

*** Hope it gives an idea of what you are trying to achieve .

Please or to participate in this conversation.