Welcome Guest, Not a member yet? Register   Sign In
Flashdata clearing after redirect
#1

Hello, 
Flashdata is clearing up after I do the redirect.
My code:
PHP Code:
    public function deleteGroup()
    {

        $model = new \App\Models\GroupModel();

        $post $this->request->getPost();
        if ($post) {
            session()->setFlashdata('success''Grupo removido com sucesso');
        }
        return redirect()->to('groups');
    

But if I remove the redirect and return a view, it works correctly:
PHP Code:
public function deleteGroup()
    {

        $model = new \App\Models\GroupModel();

        $post $this->request->getPost();
        if ($post) {
            session()->setFlashdata('success''Grupo removido com sucesso');
        }
        return view('group');
    


What am I doing wrong?
Reply
#2

Why not just: return redirect()->to('groups')->with('success', 'Grupo remivido com sucesso');
Reply
#3

(This post was last modified: 10-24-2022, 09:08 AM by Thiaxl.)

(10-24-2022, 08:00 AM)superior Wrote: Why not just:  return redirect()->to('groups')->with('success', 'Grupo remivido com sucesso');

Hello. Not Working yet. Redirect clean the flash data.
Reply
#4

You can append "->withCookies()" to the end of your redirect.


PHP Code:
    public function deleteGroup()
    {

        $model = new \App\Models\GroupModel();

        $post $this->request->getPost();
        if ($post) {
            session()->setFlashdata('success''Grupo removido com sucesso');
        }
        return redirect()->to('groups')->withCookies();
    
Reply
#5

(10-24-2022, 07:11 AM)Thiaxl Wrote: Flashdata is clearing up after I do the redirect.

How did you know that?
I think redirect() dose not clear session data.
Reply
#6

(10-24-2022, 07:11 AM)Thiaxl Wrote: Hello, 
Flashdata is clearing up after I do the redirect.
My code:
PHP Code:
    public function deleteGroup()
    {

        $model = new \App\Models\GroupModel();

        $post $this->request->getPost();
        if ($post) {
            session()->setFlashdata('success''Grupo removido com sucesso');
        }
        return redirect()->to('groups');
    

But if I remove the redirect and return a view, it works correctly:
PHP Code:
public function deleteGroup()
    {

        $model = new \App\Models\GroupModel();

        $post $this->request->getPost();
        if ($post) {
            session()->setFlashdata('success''Grupo removido com sucesso');
        }
        return view('group');
    


What am I doing wrong?

Typo? 'group' or 'groups'?
Reply
#7

What happens if you use:
PHP Code:
$session->keepFlashdata('item'); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB