validation error message in laravel
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
validation error message in laravel
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
laravel validation example
//import
use Illuminate\Support\Facades\Validator;
// single var check
$validator = Validator::make(['data' => $value],
['data' => 'string|min:1|max:10']
);
if ($validator->fails()) {
// your code
}
// array check
$validator = Validator::make(['data' => $array],
['email' => 'string|min:1|max:10'],
['username' => 'string|min:1|max:10'],
['password' => 'string|min:1|max:10'],
['...' => '...']
);
if ($validator->fails()) {
// your code
}
laravel validation
/**
* Store a new blog post.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$validatedData = $request->validate([
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);
// The blog post is valid...
}
laravel validation
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Validator;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Validator::extend('foo', function ($attribute, $value, $parameters, $validator) {
return $value == 'foo';
});
}
}
laravel validation
"foo" => "Your input was invalid!",
"accepted" => "The :attribute must be accepted.",
// The rest of the validation error messages...
validation required in laravel
Request()->validate([
'nik' => 'required',
'nama' => 'required',
'alamat' => 'required',
'notelp' => 'required',
'jk' => 'required',
'agama' => 'required',
'pekerjaan' => 'required',
'status' => 'required',
], [
'nik.required' => 'nik Wajib Diisi!',
'nama.required' => 'nama perolehan Wajib Diisi!',
'alamat.required' => 'alamat Wajib Diisi!',
'notelp.required' => 'notelp Wajib Diisi!',
'jk.required' => 'jk Wajib Diisi!',
'agama.required' => 'agama habis Wajib Diisi!',
'pekerjaan.required' => 'pekerjaan Wajib Diisi!',
'status.required' => 'status Wajib Diisi!',
]);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us