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

SigalZ's avatar
Level 5

Laravel Excel custom validation

Hello, Using laravel 12 and the package: Laravel Excel.

https://docs.laravel-excel.com/3.1/imports/validation.html

I have an excel file with these column names:

Batch, Time, Profile, Beans, In (g), Out (g)

Example for the Time value: 2026-05-17 13:39

Example for the Profile value: Brazil-5kg-Med-03

I need to check a table in the database for existing records for:

roasted_date: 2026-05-17 13:39:00

coffee_id: 3

If a record exists, I need to give an error.

In my import class I have this method:

It finds a duplicate (I get the Log debug message), but I don't get the Swal message.

I couldn't find a way to add this validation to the validation errors in the documentation, or I don't really understand their examples for complex validations, that's why I'm trying it that way.

Can someone please help?

0 likes
3 replies
ghabriel25's avatar

Did you include this in your base layout?

<body>

    {{ $slot }}

    @include('sweetalert2::index') 

</body>

Also check if there was console error

SigalZ's avatar

Yes, it is included in: resources/views/layouts/master.blade.php:

@include('layouts.admin.scripts')
@include('sweetalert2::index')

</body>
</html>

There are no errors in the console.

SigalZ's avatar

Ok, I managed to solve the issue and add the validation to the errors. So now I get it as a normal validation error, not using Swal.

If anyone is interested, in my Import class I added these methods:

Please or to participate in this conversation.