I came across a Laravel tutorial. It's about authentication system and creating login interface.
There is some strange code that I don't understand.
There is a login form submitting a post request to server to authenticate. Based on input data, it may fail with errors (Like invalid email or ...). There is a field under the form to show those errors:
@if ($errors->any())
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
@endif
PHP directives execute on server side (?), so how it shows errors after submitting the form? Page is already loaded. So how it works?
Yes, server-side. That's PHP.
Without seeing the rest of the code I have to assume but usually what happens here is, the <form action> will point to the same php page where the login form is. So after clicking on submit the same page will execute again, this time the variables for user and password will have values, so if everything is good the script will redirect to somewhere else.
If there's an error the script won't redirect, and instead reload the same page again, but this time after setting the appropriate errors on the $errors var, which your code will show.