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

ezheng's avatar

Session flash in AfterImport Laravel Excel

Hi, i am using Laravel excel 3.1 on my Inertia vue project. I am creating import function for big file using chunksize, shouldqueue and withevent. Everything work fine now, but i need to tell the user ( frontend ) that the import process already finished. How to do that? I try using flash, session, return redirect. Everyting failed.

here are my code :

class ProductsImport implements
    ToModel,
    WithHeadingRow,
    WithChunkReading,
    WithValidation,
    ShouldQueue,
    WithEvents,
    SkipsOnError,
    SkipsOnFailure
{
    use Importable, SkipsErrors, SkipsFailures, RegistersEventListeners;

    public function __construct()
    {
    }

    public function model(array $row)
    {
       // My code to store to db
    }

    public function rules(): array
    {
      // rules
    }

    public function chunkSize(): int
    {
        return 50;
    }

    public static function afterImport(AfterImport $event)
    {
			Log::info('Import Finish!)
        // Here is what i want to type to tell user that the process already finished. how to do that?	        
    }
}

Here are what i already tried :

	using return redirect()->back()->withSuccess('Imported Finish');
	or 
	Session::flash('success', 'Imported Finish');
	or event 
	i try to return route('xxxxxxx')
0 likes
6 replies
NoLAstNamE's avatar

I think you should do that in the controller.

Excel::import(new ProductsImport, $request->file('file')->store('temp'));

return redirect()->back()->withSuccess('Imported Finish');
ezheng's avatar

@krisi_gjika thanks for the reply. My import process is using shouldqueue and chunksize, if the rows is about 100k rows, it will takes times because the process is on background. So if i create like that, it will directly triger 'Imported finish', but actually the process is not finish, maybe even hasnt been start.

krisi_gjika's avatar

@ezheng you can either have your frontend client ping your backend for status updates every x seconds, notify via some other channel, like email, if the process takes too long, or set up web sockets for live updates.

dayCod's avatar

can you dd the session key after redirect ? i want to see the result, is it null ?

Please or to participate in this conversation.