withSuccess doesn't work after redirect

Author: schel4okCreated Mar 13, 2022Updated Dec 16, 2024
  • Laravel Version: 8.52.0
  • PHP Version: 8.0.2
  • Laravel-admin: 1.8.13

Description:

in controller I have index method where I have few buttons to import database from xls file

    public function index(Content $content)
    {
        return $content
            ->title('Import & Export')
            ->description('Laravel excel')
            ->view('admin.myadmin.import.index');
    }

If I click on News button then importNews() method is fired and I expect to see success message when job is done.

    public function importNews()
    {
        $this->news();
        $news= $this->news->rows;

        return redirect()
            ->back()
            ->withSuccess($news.' news imported succesfully');

But instead I see following error message

ViewException In alerts.blade.php line 22 :
[  Call to a member function get() on string (View: /var/www/dev.local/resources/views/admin/partials/alerts.blade.php)]()

If I change like that I have no problems.

    public function importNews()
    {
        $this->news();
        $news= $this->news->rows;

        return $content
            ->title('Import & Export')
            ->description('Laravel excel')
            ->view('admin.myadmin.import.index', compact('news'))
            ->withSuccess($news.' news imported succesfully');

It seems that withSuccess doesn't work after redirect. Can someone help with this?