Parse error: syntax error, unexpected end of file, expecting elseif (T_ELSEIF) or else (T_ELSE) or endif (T_ENDIF)
When you encounter a PHP parse error stating syntax error, unexpected end of file while working with Blade templates, the compiler is screaming that it expected a closing directive but hit the end of the script instead. In your specific case, the error log explicitly mentions expecting elseif, else, or endif. This tells us exactly where the logic flow broke down: inside an @if block that was never closed with its corresponding @endif.
Looking at the provided customers_blade.php view, the code structure immediately reveals the culprit. You open a conditional check for a success message using @if(Session::has('success')). Following that is a nested check for a warning message: @if(Session::has(warning)). However, the logic never resolves. The inner block closes with @endif, but the outer block containing the success message remains open all the way to the end of the file.
Here is the problematic segment from your code:
@if(Session::has('success'))
<div class="alert alert-success">
{{Session :: get('message')}}
</div>
@if(Session::has(warning))
<div class="alert alert-warning">
{{Session::get('message')}}
</div>
@endif
<!-- Missing @endif here -->
<div class="form-group">
Because the parser reads to the bottom of the file without finding the matching @endif for the first condition, it throws the syntax error you are seeing. The solution is straightforward: add @endif before the <div class="form-group"> element that starts the file input label.
Beyond fixing the immediate syntax error, there are a few architectural considerations worth addressing in your implementation of the customer import blade. First, notice the variable inconsistency between the two alerts. You use Session::get('message') for the warning alert but Session :: get('message') for the success alert. While this might work if the session key is strictly 'message' for both, it is often best practice to store distinct keys like 'success_message' and 'warning_message' or ensure your controller explicitly sets the same key name. Mixing these up can lead to silent failures where alerts don't render even if the code is syntactically correct.
Secondly, look at how you are displaying errors. You have this line:{!! $error->first('products','<p class="alert alert-danger">:message</p') !!}
This assumes that $errors (the standard Laravel error bag) is available in your view and specifically contains a key named products. If your form validation fails on a different field, or if you are passing a custom $error object that isn't an instance of Illuminate\Support\MessageBag, this will likely result in a variable undefined error rather than a parse error. It is generally safer to rely on the global Laravel error bag unless you have a specific reason to pass a custom collection.
Finally, consider the logic of displaying both success and warning alerts simultaneously. In many import workflows, you might want to show a success message ("10 rows imported") alongside a warning ("2 rows skipped due to invalid email"). Your current structure allows for this, provided the syntax is fixed. However, ensure that your controller is actually populating these session variables before redirecting back to this view. If the controller sets Session::put('warning', $message) but you are checking Session::has(warning) (missing quotes around the key name in your second check), the alert won't show, and the user might be confused by a success message with no context.
Fixing the missing directive restores the file's integrity, allowing your import/export functionality to render correctly. Once the syntax error is resolved, you can focus on refining the session handling logic to ensure users receive clear feedback during the data import process.