Get error message from Laravel validation
<p>I use Laravel built-in validator and I want to get the first error message</p>

<pre><code>if ($validator-&gt;fails()) {
     $error = $validator-&gt;messages()-&gt;toJson();
     .....
}
</code></pre>

<p>This is the result when I print error</p>

<pre><code>{"name":["The name must be at least 5 characters."],"alamat":["The address must be at least 5 characters."]}
</code></pre>

<p>In the example above, I want to get the first error, which is "The name must be at least 5 characters.". How can I do that?</p>