Tempat Belajar Bahasa Pemrograman Dari Dasar
Penulis : Zulfikar Kategori : Uncategorized
use Illuminate\Support\Facades\Validator;
$validator->setAttributeNames();
App/Http/Controllers/Login.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class Login extends Controller {
public function index(Request $request) {
$validator = Validator::make($request->all(), [
'username' => 'required|min:3',
'password' => 'required|min:6'
], [
'required' => ':attribute tidak boleh kosong!',
'min' => ':attribute minimal :min karakter!'
]);
$validator->setAttributeNames(
[
'username' => 'Username',
'password' => 'Password'
]
);
if ($validator->fails()) {
return response()->json(['sts' => false, 'msg' => $validator->errors()], 400);
}
return response()->json(['sts' => true, 'msg' => 'sukses']);
}
}