{"id":74488,"date":"2024-06-27T14:31:12","date_gmt":"2024-06-27T07:31:12","guid":{"rendered":"https:\/\/itviec.com\/blog\/?p=74488"},"modified":"2024-06-27T14:31:12","modified_gmt":"2024-06-27T07:31:12","slug":"laravel-validation-la-gi","status":"publish","type":"post","link":"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/","title":{"rendered":"Laravel Validation: Chi ti\u1ebft c\u00e1c quy t\u1eafc v\u00e0 c\u00e1ch \u00e1p d\u1ee5ng hi\u1ec7u qu\u1ea3"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">N\u1ed9i dung b\u00e0i vi\u1ebft<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/#Laravel_Validation_la_gi\" >Laravel Validation l\u00e0 g\u00ec?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/#Cac_quy_tac_Laravel_Validation\" >C\u00e1c quy t\u1eafc Laravel Validation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/#Huong_dan_cach_tao_quy_tac_Laravel_validation\" >H\u01b0\u1edbng d\u1eabn c\u00e1ch t\u1ea1o quy t\u1eafc Laravel validation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/#Cach_ap_dung_cac_quy_tac_Laravel_Validation\" >C\u00e1ch \u00e1p d\u1ee5ng c\u00e1c quy t\u1eafc Laravel Validation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/#Cach_ap_dung_Laravel_Validation_de_xac_thuc_mang_Array\" >C\u00e1ch \u00e1p d\u1ee5ng Laravel Validation \u0111\u1ec3 x\u00e1c th\u1ef1c m\u1ea3ng (Array)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/#Cach_ap_dung_Laravel_Validation_de_kiem_duyet_file\" >C\u00e1ch \u00e1p d\u1ee5ng Laravel Validation \u0111\u1ec3 ki\u1ec3m duy\u1ec7t file<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/#Cach_ap_dung_Laravel_Validation_de_xac_thuc_mat_khau\" >C\u00e1ch \u00e1p d\u1ee5ng Laravel Validation \u0111\u1ec3 x\u00e1c th\u1ef1c m\u1eadt kh\u1ea9u<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/#Cau_hoi_thuong_gap_ve_Laravel_Validation\" >C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 Laravel Validation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/#Tong_ket_Laravel_Validation\" >T\u1ed5ng k\u1ebft Laravel Validation<\/a><\/li><\/ul><\/nav><\/div>\n<p><em><strong>Trong ph\u00e1t tri\u1ec3n \u1ee9ng d\u1ee5ng hi\u1ec7n \u0111\u1ea1i, vi\u1ec7c \u0111\u1ea3m b\u1ea3o d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o l\u00e0 h\u1ee3p l\u1ec7 v\u00e0 ch\u00ednh x\u00e1c l\u00e0 v\u1ea5n \u0111\u1ec1 quan tr\u1ecdng h\u00e0ng \u0111\u1ea7u. Laravel &#8211; m\u1ed9t framework PHP ph\u1ed5 bi\u1ebfn, cung c\u1ea5p nhi\u1ec1u ph\u01b0\u01a1ng th\u1ee9c validation (ki\u1ec3m tra d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o) m\u1ea1nh m\u1ebd v\u00e0 to\u00e0n di\u1ec7n. B\u00e0i vi\u1ebft n\u00e0y s\u1ebd h\u01b0\u1edbng d\u1eabn b\u1ea1n c\u00e1ch t\u1ea1o v\u00e0 \u00e1p d\u1ee5ng hi\u1ec7u qu\u1ea3 Laravel validation, t\u1eeb s\u1eed d\u1ee5ng c\u00e1c quy t\u1eafc x\u00e1c th\u1ef1c c\u00f3 s\u1eb5n \u0111\u1ebfn vi\u1ec7c t\u1ea1o ra c\u00e1c quy t\u1eafc t\u00f9y ch\u1ec9nh, gi\u00fap b\u1ea3o v\u1ec7 \u1ee9ng d\u1ee5ng c\u1ee7a b\u1ea1n kh\u1ecfi c\u00e1c d\u1eef li\u1ec7u kh\u00f4ng mong mu\u1ed1n v\u00e0 \u0111\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n c\u1ee7a h\u1ec7 th\u1ed1ng.<\/strong><\/em><\/p>\n<p><span style=\"font-weight: 400;\">\u0110\u1ecdc b\u00e0i vi\u1ebft \u0111\u1ec3 n\u1eafm r\u00f5:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Laravel validation l\u00e0 g\u00ec?<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">T\u1ea5t c\u1ea3 c\u00e1c lo\u1ea1i quy t\u1eafc Laravel validation v\u00e0 ch\u1ee9c n\u0103ng c\u1ee7a ch\u00fang<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e1c c\u00e1ch t\u1ea1o v\u00e0 \u00e1p d\u1ee5ng Laravel validation ph\u1ed5 bi\u1ebfn nh\u1ea5t<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Laravel_Validation_la_gi\"><\/span><b>Laravel Validation l\u00e0 g\u00ec?<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Laravel validation l\u00e0 vi\u1ec7c x\u00e1c th\u1ef1c ho\u1eb7c ki\u1ec3m tra d\u1eef li\u1ec7u trong framework Laravel. Vi\u1ec7c n\u00e0y gi\u00fap \u0111\u1ea3m b\u1ea3o d\u1eef li\u1ec7u h\u1ee3p l\u1ec7, ch\u00ednh x\u00e1c, \u0111\u00e1p \u1ee9ng m\u1ecdi y\u00eau c\u1ea7u c\u1ee7a h\u1ec7 th\u1ed1ng, \u0111\u1ed3ng th\u1eddi gi\u00fap duy tr\u00ec t\u00ednh nh\u1ea5t qu\u00e1n c\u1ee7a d\u1eef li\u1ec7u v\u00e0 tr\u00e1nh c\u00e1c l\u1ed7 h\u1ed5ng b\u1ea3o m\u1eadt.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Laravel l\u00e0 c\u00f4ng c\u1ee5 gi\u00fap cho vi\u1ec7c x\u00e1c th\u1ef1c d\u1eef li\u1ec7u tr\u1edf n\u00ean d\u1ec5 d\u00e0ng v\u00e0 tr\u1ef1c quan v\u00ec n\u00f3 tu\u00e2n theo ki\u1ebfn tr\u00fac model-view-controller (MVC) v\u00e0 cung c\u1ea5p nhi\u1ec1u ph\u01b0\u01a1ng th\u1ee9c \u0111\u1ec3 ki\u1ec3m tra d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o to\u00e0n di\u1ec7n. M\u1ed7i ph\u01b0\u01a1ng th\u1ee9c validation trong Laravel \u0111\u1ec1u c\u00f3 \u01b0u v\u00e0 nh\u01b0\u1ee3c \u0111i\u1ec3m ri\u00eang, s\u1ef1 \u0111a d\u1ea1ng n\u00e0y cho ph\u00e9p b\u1ea1n l\u1ef1a ch\u1ecdn c\u00e1ch ti\u1ebfp c\u1eadn t\u1ed1t nh\u1ea5t cho nhu c\u1ea7u c\u1ee7a m\u00ecnh.<\/span><\/p>\n<blockquote><p><em>\u0110\u1ecdc th\u00eam: <a href=\"https:\/\/itviec.com\/blog\/laravel-la-gi\/\" target=\"_blank\" rel=\"noopener\"><strong>Laravel l\u00e0 g\u00ec? T\u1ed5ng quan v\u1ec1 Laravel A-Z cho ng\u01b0\u1eddi m\u1edbi b\u1eaft \u0111\u1ea7u<\/strong><\/a><\/em><\/p><\/blockquote>\n<h2><span class=\"ez-toc-section\" id=\"Cac_quy_tac_Laravel_Validation\"><\/span><b>C\u00e1c quy t\u1eafc Laravel Validation<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">D\u01b0\u1edbi \u0111\u00e2y l\u00e0 danh s\u00e1ch t\u1ea5t c\u1ea3 c\u00e1c quy t\u1eafc x\u00e1c th\u1ef1c c\u00f3 s\u1eb5n trong Laravel v\u00e0 ch\u1ee9c n\u0103ng c\u1ee7a ch\u00fang:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Quy t\u1eafc Laravel Validation<\/b><\/td>\n<td><b>Gi\u1ea3i th\u00edch ch\u1ee9c n\u0103ng<\/b><\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>accepted<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 &#8220;yes&#8221;, &#8220;on&#8221;, 1, &#8220;1&#8221;, true, ho\u1eb7c &#8220;true&#8221;.\u00a0<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Quy t\u1eafc n\u00e0y h\u1eefu \u00edch cho vi\u1ec7c x\u00e1c th\u1ef1c vi\u1ec7c ng\u01b0\u1eddi d\u00f9ng ch\u1ea5p nh\u1eadn &#8220;\u0110i\u1ec1u kho\u1ea3n d\u1ecbch v\u1ee5\/ Terms of Service&#8221; ho\u1eb7c c\u00e1c tr\u01b0\u1eddng t\u01b0\u01a1ng t\u1ef1.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>accepted_if<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Ch\u1ee9c n\u0103ng c\u1ee7a accepted_if gi\u1ed1ng v\u1edbi accepted ch\u1ec9 c\u00f3 \u0111i\u1ec3m kh\u00e1c l\u00e0 ch\u00fang ch\u1ec9 ki\u1ec3m tra gi\u00e1 tr\u1ecb c\u1ee7a tr\u01b0\u1eddng n\u1ebfu m\u1ed9t tr\u01b0\u1eddng kh\u00e1c c\u00f3 gi\u00e1 tr\u1ecb c\u1ee5 th\u1ec3.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>active_url<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 b\u1ea3n ghi A ho\u1eb7c AAAA h\u1ee3p l\u1ec7 theo h\u00e0m dns_get_record c\u1ee7a PHP. T\u00ean mi\u1ec1n c\u1ee7a URL \u0111\u01b0\u1ee3c cung c\u1ea5p s\u1ebd \u0111\u01b0\u1ee3c tr\u00edch xu\u1ea5t b\u1eb1ng h\u00e0m parse_url c\u1ee7a PHP tr\u01b0\u1edbc khi \u0111\u01b0\u1ee3c truy\u1ec1n v\u00e0o dns_get_record.\u00a0<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Quy t\u1eafc active_url ch\u1ec9 ki\u1ec3m tra xem URL c\u00f3 b\u1ea3n ghi DNS h\u1ee3p l\u1ec7 hay kh\u00f4ng, kh\u00f4ng \u0111\u1ea3m b\u1ea3o r\u1eb1ng URL d\u1eabn \u0111\u1ebfn m\u1ed9t trang web ho\u1ea1t \u0111\u1ed9ng.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>after (date)<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t gi\u00e1 tr\u1ecb sau m\u1ed9t ng\u00e0y tham chi\u1ebfu. C\u00e1c ng\u00e0y s\u1ebd \u0111\u01b0\u1ee3c truy\u1ec1n v\u00e0o h\u00e0m strtotime c\u1ee7a PHP \u0111\u1ec3 \u0111\u01b0\u1ee3c chuy\u1ec3n \u0111\u1ed5i th\u00e0nh m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng DateTime h\u1ee3p l\u1ec7:<\/span><\/p>\n<p style=\"text-align: left;\"><b>&#8216;start_date&#8217; =&gt; &#8216;required|date|after:tomorrow&#8217;<\/b><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Thay v\u00ec truy\u1ec1n v\u00e0o m\u1ed9t chu\u1ed7i ng\u00e0y \u0111\u1ec3 \u0111\u01b0\u1ee3c \u0111\u00e1nh gi\u00e1 b\u1edfi strtotime, b\u1ea1n c\u00f3 th\u1ec3 ch\u1ec9 \u0111\u1ecbnh m\u1ed9t tr\u01b0\u1eddng kh\u00e1c \u0111\u1ec3 so s\u00e1nh v\u1edbi ng\u00e0y:<\/span><\/p>\n<p style=\"text-align: left;\"><b>&#8216;finish_date&#8217; =&gt; &#8216;required|date|after:start_date&#8217;<\/b><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Quy t\u1eafc after ch\u1ec9 ki\u1ec3m tra th\u1ee9 t\u1ef1 th\u1eddi gian c\u1ee7a c\u00e1c ng\u00e0y, kh\u00f4ng \u0111\u1ea3m b\u1ea3o r\u1eb1ng c\u00e1c ng\u00e0y c\u00f3 h\u1ee3p l\u00fd hay kh\u00f4ng. V\u00ed d\u1ee5: after:2024-01-01 s\u1ebd h\u1ee3p l\u1ec7 cho c\u1ea3 2024-02-01 v\u00e0 2023-12-31.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>after_or_equal (date)<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Quy t\u1eafc n\u00e0y g\u1ea7n gi\u1ed1ng v\u1edbi quy t\u1eafc after, ch\u1ec9 kh\u00e1c l\u00e0 tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t gi\u00e1 tr\u1ecb sau ho\u1eb7c b\u1eb1ng v\u1edbi ng\u00e0y tham chi\u1ebfu.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Quy t\u1eafc after_or_equal ch\u1ec9 ki\u1ec3m tra th\u1ee9 t\u1ef1 th\u1eddi gian c\u1ee7a c\u00e1c ng\u00e0y, kh\u00f4ng \u0111\u1ea3m b\u1ea3o r\u1eb1ng c\u00e1c ng\u00e0y c\u00f3 h\u1ee3p l\u00fd hay kh\u00f4ng. V\u00ed d\u1ee5: after_or_equal:2024-01-01 s\u1ebd h\u1ee3p l\u1ec7 cho c\u1ea3 2024-02-01, 2024-01-01, v\u00e0 2023-12-31.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>alpha<\/b><\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i ho\u00e0n to\u00e0n l\u00e0 c\u00e1c k\u00fd t\u1ef1 b\u1ea3ng ch\u1eef c\u00e1i Unicode c\u00f3 trong <\/span><a href=\"https:\/\/util.unicode.org\/UnicodeJsps\/list-unicodeset.jsp?a=%5B%3AL%3A%5D&amp;g=&amp;i=\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">\\p{L}<\/span><\/a><span style=\"font-weight: 400;\"> v\u00e0 <\/span><a href=\"https:\/\/util.unicode.org\/UnicodeJsps\/list-unicodeset.jsp?a=%5B%3AM%3A%5D&amp;g=&amp;i=\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">\\p{M}<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u0110\u1ec3 gi\u1edbi h\u1ea1n quy t\u1eafc x\u00e1c th\u1ef1c n\u00e0y ch\u1ec9 trong ph\u1ea1m vi k\u00fd t\u1ef1 ASCII (a-z v\u00e0 A-Z), b\u1ea1n c\u00f3 th\u1ec3 cung c\u1ea5p t\u00f9y ch\u1ecdn ascii cho quy t\u1eafc x\u00e1c th\u1ef1c:<\/span><\/p>\n<p><b>&#8216;username&#8217; =&gt; &#8216;alpha:ascii&#8217;,<\/b><\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>alpha_dash<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i ho\u00e0n to\u00e0n l\u00e0 c\u00e1c k\u00fd t\u1ef1 ch\u1eef v\u00e0 s\u1ed1 Unicode ch\u1ee9a trong <\/span><a href=\"https:\/\/util.unicode.org\/UnicodeJsps\/list-unicodeset.jsp?a=%5B%3AL%3A%5D&amp;g=&amp;i=\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">\\p{L}<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/util.unicode.org\/UnicodeJsps\/list-unicodeset.jsp?a=%5B%3AM%3A%5D&amp;g=&amp;i=\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">\\p{M}<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/util.unicode.org\/UnicodeJsps\/list-unicodeset.jsp?a=%5B%3AN%3A%5D&amp;g=&amp;i=\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">\\p{N}<\/span><\/a><span style=\"font-weight: 400;\">, c\u0169ng nh\u01b0 d\u1ea5u g\u1ea1ch ngang ASCII (-) v\u00e0 d\u1ea5u g\u1ea1ch d\u01b0\u1edbi ASCII (_).<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">\u0110\u1ec3 gi\u1edbi h\u1ea1n quy t\u1eafc x\u00e1c th\u1ef1c n\u00e0y ch\u1ec9 trong ph\u1ea1m vi k\u00fd t\u1ef1 ASCII (a-z v\u00e0 A-Z), b\u1ea1n c\u00f3 th\u1ec3 cung c\u1ea5p t\u00f9y ch\u1ecdn ascii cho quy t\u1eafc x\u00e1c th\u1ef1c:<\/span><\/p>\n<p style=\"text-align: left;\"><b>&#8216;username&#8217; =&gt; &#8216;alpha_dash:ascii&#8217;,<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>alpha_num\u00a0<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i ho\u00e0n to\u00e0n l\u00e0 c\u00e1c k\u00fd t\u1ef1 ch\u1eef v\u00e0 s\u1ed1 Unicode ch\u1ee9a trong <\/span><a href=\"https:\/\/util.unicode.org\/UnicodeJsps\/list-unicodeset.jsp?a=%5B%3AL%3A%5D&amp;g=&amp;i=\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">\\p{L}<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/util.unicode.org\/UnicodeJsps\/list-unicodeset.jsp?a=%5B%3AM%3A%5D&amp;g=&amp;i=\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">\\p{M}<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/util.unicode.org\/UnicodeJsps\/list-unicodeset.jsp?a=%5B%3AN%3A%5D&amp;g=&amp;i=\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">\\p{N}<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">\u0110\u1ec3 gi\u1edbi h\u1ea1n quy t\u1eafc x\u00e1c th\u1ef1c n\u00e0y ch\u1ec9 trong ph\u1ea1m vi k\u00fd t\u1ef1 ASCII (a-z v\u00e0 A-Z), b\u1ea1n c\u00f3 th\u1ec3 cung c\u1ea5p t\u00f9y ch\u1ecdn ascii cho quy t\u1eafc x\u00e1c th\u1ef1c:<\/span><\/p>\n<p style=\"text-align: left;\"><b>&#8216;username&#8217; =&gt; &#8216;alpha_num:ascii&#8217;,<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>array<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t m\u1ea3ng PHP.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Khi b\u1ea1n cung c\u1ea5p th\u00eam gi\u00e1 tr\u1ecb cho quy t\u1eafc array, m\u1ed7i kh\u00f3a trong m\u1ea3ng \u0111\u1ea7u v\u00e0o ph\u1ea3i c\u00f3 m\u1eb7t trong danh s\u00e1ch gi\u00e1 tr\u1ecb \u0111\u01b0\u1ee3c cung c\u1ea5p cho quy t\u1eafc. Trong v\u00ed d\u1ee5 sau, kh\u00f3a admin trong m\u1ea3ng \u0111\u1ea7u v\u00e0o kh\u00f4ng h\u1ee3p l\u1ec7 v\u00ec n\u00f3 kh\u00f4ng c\u00f3 trong danh s\u00e1ch c\u00e1c gi\u00e1 tr\u1ecb \u0111\u01b0\u1ee3c cung c\u1ea5p cho quy t\u1eafc array:<\/span><\/p>\n<p style=\"text-align: left;\"><strong>use Illuminate\\Support\\Facades\\Validator;<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>$input = [<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>\u00a0\u00a0\u00a0\u00a0&#8216;user&#8217; =&gt; [<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;name&#8217; =&gt; &#8216;Taylor Otwell&#8217;,<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;username&#8217; =&gt; &#8216;taylorotwell&#8217;,<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;admin&#8217; =&gt; true,<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>\u00a0\u00a0\u00a0\u00a0],<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>];<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>Validator::make($input, [<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>\u00a0\u00a0\u00a0\u00a0&#8216;user&#8217; =&gt; &#8216;array:name,username&#8217;,<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>]);<\/strong><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Trong m\u1ecdi tr\u01b0\u1eddng h\u1ee3p, b\u1ea1n n\u00ean ch\u1ec9 \u0111\u1ecbnh c\u00e1c kh\u00f3a m\u1ea3ng \u0111\u01b0\u1ee3c ph\u00e9p c\u00f3 m\u1eb7t trong m\u1ea3ng c\u1ee7a b\u1ea1n.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>ascii\u00a0<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i ho\u00e0n to\u00e0n l\u00e0 c\u00e1c k\u00fd t\u1ef1 ASCII 7-bit.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>bail\u00a0<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">D\u1eebng vi\u1ec7c ch\u1ea1y c\u00e1c quy t\u1eafc x\u00e1c th\u1ef1c cho tr\u01b0\u1eddng sau khi g\u1eb7p l\u1ed7i x\u00e1c th\u1ef1c \u0111\u1ea7u ti\u00ean.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">L\u01b0u \u00fd: Quy t\u1eafc bail ch\u1ec9 d\u1eebng vi\u1ec7c x\u00e1c th\u1ef1c cho m\u1ed9t tr\u01b0\u1eddng c\u1ee5 th\u1ec3 khi g\u1eb7p l\u1ed7i x\u00e1c th\u1ef1c, c\u00f2n ph\u01b0\u01a1ng th\u1ee9c stopOnFirstFailure s\u1ebd th\u00f4ng b\u00e1o cho validator r\u1eb1ng n\u00f3 n\u00ean d\u1eebng vi\u1ec7c x\u00e1c th\u1ef1c t\u1ea5t c\u1ea3 c\u00e1c thu\u1ed9c t\u00ednh khi g\u1eb7p l\u1ed7i x\u00e1c th\u1ef1c \u0111\u1ea7u ti\u00ean:<\/span><\/p>\n<p><b>if ($validator-&gt;stopOnFirstFailure()-&gt;fails()) {<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0\u00a0\/\/ &#8230;<\/b><\/p>\n<p><b>}<\/b><\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>Before (date)<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t gi\u00e1 tr\u1ecb tr\u01b0\u1edbc ng\u00e0y tham chi\u1ebfu. C\u00e1c ng\u00e0y s\u1ebd \u0111\u01b0\u1ee3c truy\u1ec1n v\u00e0o h\u00e0m strtotime c\u1ee7a PHP \u0111\u1ec3 \u0111\u01b0\u1ee3c chuy\u1ec3n \u0111\u1ed5i th\u00e0nh m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng DateTime h\u1ee3p l\u1ec7.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Ngo\u00e0i ra, t\u01b0\u01a1ng t\u1ef1 nh\u01b0 quy t\u1eafc after, t\u00ean c\u1ee7a m\u1ed9t tr\u01b0\u1eddng kh\u00e1c \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c cung c\u1ea5p l\u00e0m gi\u00e1 tr\u1ecb c\u1ee7a date.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>Before_or_equal (date)<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">T\u01b0\u01a1ng t\u1ef1 nh\u01b0 quy t\u1eafc before, ch\u1ec9 kh\u00e1c l\u00e0 tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t gi\u00e1 tr\u1ecb tr\u01b0\u1edbc ho\u1eb7c b\u1eb1ng v\u1edbi ng\u00e0y tham chi\u1ebfu.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>Between (min, max)<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 k\u00edch th\u01b0\u1edbc n\u1eb1m gi\u1eefa gi\u00e1 tr\u1ecb min v\u00e0 max \u0111\u00e3 cho (bao g\u1ed3m c\u1ea3 hai gi\u00e1 tr\u1ecb n\u00e0y). Chu\u1ed7i, s\u1ed1, m\u1ea3ng v\u00e0 t\u1ec7p tin s\u1ebd \u0111\u01b0\u1ee3c \u0111\u00e1nh gi\u00e1 t\u01b0\u01a1ng t\u1ef1 nh\u01b0 quy t\u1eafc size.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Quy t\u1eafc between ch\u1ec9 ki\u1ec3m tra ph\u1ea1m vi gi\u00e1 tr\u1ecb c\u1ee7a tr\u01b0\u1eddng, kh\u00f4ng \u0111\u1ea3m b\u1ea3o r\u1eb1ng gi\u00e1 tr\u1ecb c\u00f3 h\u1ee3p l\u00fd hay kh\u00f4ng. V\u00ed d\u1ee5: between:1,10 s\u1ebd h\u1ee3p l\u1ec7 cho c\u1ea3 5, 7.5, v\u00e0 10.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>boolean\u00a0<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i chuy\u1ec3n \u0111\u1ed5i \u0111\u01b0\u1ee3c th\u00e0nh ki\u1ec3u boolean. C\u00e1c gi\u00e1 tr\u1ecb \u0111\u1ea7u v\u00e0o \u0111\u01b0\u1ee3c ch\u1ea5p nh\u1eadn l\u00e0 true, false, 1, 0, &#8220;1&#8221;, v\u00e0 &#8220;0&#8221;.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>confirmed\u00a0<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 m\u1ed9t tr\u01b0\u1eddng t\u01b0\u01a1ng \u1ee9ng \u0111\u1ec3 x\u00e1c nh\u1eadn, \u0111\u01b0\u1ee3c \u0111\u1eb7t t\u00ean theo d\u1ea1ng {field}_confirmation. V\u00ed d\u1ee5, n\u1ebfu tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c l\u00e0 password, th\u00ec ph\u1ea3i c\u00f3 m\u1ed9t tr\u01b0\u1eddng password_confirmation t\u01b0\u01a1ng \u1ee9ng trong \u0111\u1ea7u v\u00e0o.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>contains<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t m\u1ea3ng ch\u1ee9a t\u1ea5t c\u1ea3 c\u00e1c gi\u00e1 tr\u1ecb tham s\u1ed1 \u0111\u00e3 cho.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>current_password\u00a0<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i kh\u1edbp v\u1edbi m\u1eadt kh\u1ea9u c\u1ee7a ng\u01b0\u1eddi d\u00f9ng \u0111\u00e3 x\u00e1c th\u1ef1c. B\u1ea1n c\u00f3 th\u1ec3 ch\u1ec9 \u0111\u1ecbnh m\u1ed9t authentication guard (b\u1ed9 b\u1ea3o v\u1ec7 x\u00e1c th\u1ef1c) b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng tham s\u1ed1 \u0111\u1ea7u ti\u00ean c\u1ee7a quy t\u1eafc:<\/span><\/p>\n<p style=\"text-align: left;\"><b>&#8216;password&#8217; =&gt; &#8216;current_password:api&#8217;<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>date\u00a0<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t ng\u00e0y h\u1ee3p l\u1ec7 theo \u0111\u1ecbnh d\u1ea1ng tuy\u1ec7t \u0111\u1ed1i v\u00e0 c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c x\u1eed l\u00fd b\u1edfi h\u00e0m strtotime c\u1ee7a PHP.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>date_equals (date)<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i b\u1eb1ng v\u1edbi ng\u00e0y \u0111\u00e3 cho. C\u00e1c ng\u00e0y s\u1ebd \u0111\u01b0\u1ee3c truy\u1ec1n v\u00e0o h\u00e0m strtotime c\u1ee7a PHP \u0111\u1ec3 \u0111\u01b0\u1ee3c chuy\u1ec3n \u0111\u1ed5i th\u00e0nh m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng DateTime h\u1ee3p l\u1ec7.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>date_format<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i kh\u1edbp v\u1edbi m\u1ed9t trong c\u00e1c \u0111\u1ecbnh d\u1ea1ng ng\u00e0y \u0111\u00e3 cho. B\u1ea1n ch\u1ec9 n\u00ean s\u1eed d\u1ee5ng date ho\u1eb7c date_format khi x\u00e1c th\u1ef1c m\u1ed9t tr\u01b0\u1eddng ng\u00e0y, kh\u00f4ng n\u00ean s\u1eed d\u1ee5ng c\u1ea3 hai.\u00a0<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Quy t\u1eafc date_format s\u1eed d\u1ee5ng h\u00e0m DateTime::createFromFormat c\u1ee7a PHP \u0111\u1ec3 c\u1ed1 g\u1eafng chuy\u1ec3n \u0111\u1ed5i gi\u00e1 tr\u1ecb c\u1ee7a tr\u01b0\u1eddng sang \u0111\u1ecbnh d\u1ea1ng ng\u00e0y \u0111\u00e3 cho.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>decimal (min, max)<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 s\u1ed1 v\u00e0 ph\u1ea3i ch\u1ee9a m\u1ed9t l\u01b0\u1ee3ng s\u1ed1 ch\u1eef s\u1ed1 th\u1eadp ph\u00e2n nh\u1ea5t \u0111\u1ecbnh:<\/span><\/p>\n<p style=\"text-align: left;\"><b>\/\/ Ph\u1ea3i c\u00f3 \u0111\u00fang hai ch\u1eef s\u1ed1 th\u1eadp ph\u00e2n (9.99)&#8230;<\/b><\/p>\n<p style=\"text-align: left;\"><b>&#8216;price&#8217; =&gt; &#8216;decimal:2&#8217;<\/b><\/p>\n<p style=\"text-align: left;\"><b>\/\/ Ph\u1ea3i c\u00f3 t\u1eeb 2 \u0111\u1ebfn 4 ch\u1eef s\u1ed1 th\u1eadp ph\u00e2n&#8230;<\/b><\/p>\n<p style=\"text-align: left;\"><b>&#8216;price&#8217; =&gt; &#8216;decimal:2,4&#8217;<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>declined\u00a0<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 gi\u00e1 tr\u1ecb l\u00e0 &#8220;no&#8221;, &#8220;off&#8221;, 0, &#8220;0&#8221;, false ho\u1eb7c &#8220;false&#8221;.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">N\u1ebfu gi\u00e1 tr\u1ecb c\u1ee7a tr\u01b0\u1eddng kh\u1edbp v\u1edbi m\u1ed9t trong c\u00e1c gi\u00e1 tr\u1ecb tr\u00ean, quy t\u1eafc declined s\u1ebd tr\u1ea3 v\u1ec1 true.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>declined_if<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 &#8220;no&#8221;, &#8220;off&#8221;, 0, &#8220;0&#8221;, false ho\u1eb7c &#8220;false&#8221; n\u1ebfu m\u1ed9t tr\u01b0\u1eddng kh\u00e1c \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c c\u00f3 gi\u00e1 tr\u1ecb b\u1eb1ng v\u1edbi gi\u00e1 tr\u1ecb \u0111\u00e3 ch\u1ec9 \u0111\u1ecbnh.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>different (field)<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 gi\u00e1 tr\u1ecb kh\u00e1c v\u1edbi tr\u01b0\u1eddng field \u0111\u00e3 cho.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>digits (value)<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">S\u1ed1 nguy\u00ean \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 \u0111\u1ed9 d\u00e0i ch\u00ednh x\u00e1c l\u00e0 value \u0111\u00e3 cho.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>digits_between (min, max)<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">S\u1ed1 nguy\u00ean \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 \u0111\u1ed9 d\u00e0i n\u1eb1m gi\u1eefa min v\u00e0 max \u0111\u00e3 cho.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>dimensions\u00a0<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">File \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 h\u00ecnh \u1ea3nh v\u00e0 \u0111\u00e1p \u1ee9ng c\u00e1c \u0111i\u1ec1u ki\u1ec7n v\u1ec1 k\u00edch th\u01b0\u1edbc theo c\u00e1c tham s\u1ed1 \u0111\u01b0\u1ee3c cung c\u1ea5p cho quy t\u1eafc:<\/span><\/p>\n<p><b>&#8216;avatar&#8217; =&gt; &#8216;dimensions:min_width=100,min_height=200&#8217;<\/b><\/p>\n<p><span style=\"font-weight: 400;\">C\u00e1c \u0111i\u1ec1u ki\u1ec7n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng bao g\u1ed3m: min_width (chi\u1ec1u r\u1ed9ng t\u1ed1i thi\u1ec3u), max_width (chi\u1ec1u r\u1ed9ng t\u1ed1i \u0111a), min_height (chi\u1ec1u cao t\u1ed1i thi\u1ec3u), max_height (chi\u1ec1u cao t\u1ed1i \u0111a), width (chi\u1ec1u r\u1ed9ng), height (chi\u1ec1u cao), ratio (t\u1ef7 l\u1ec7).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ratio \u0111\u01b0\u1ee3c bi\u1ec3u di\u1ec5n d\u01b0\u1edbi d\u1ea1ng chi\u1ec1u r\u1ed9ng chia cho chi\u1ec1u cao, theo ki\u1ec3u ph\u00e2n s\u1ed1 (3\/2) ho\u1eb7c s\u1ed1 th\u1eadp ph\u00e2n (1.5). Th\u00eam ratio v\u00e0o quy t\u1eafc dimensions nh\u01b0 sau:<\/span><\/p>\n<p><b>&#8216;avatar&#8217; =&gt; &#8216;dimensions:ratio=3\/2&#8217;<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Do quy t\u1eafc dimensions y\u00eau c\u1ea7u nhi\u1ec1u tham s\u1ed1, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng ph\u01b0\u01a1ng th\u1ee9c Rule::dimensions \u0111\u1ec3 x\u00e2y d\u1ef1ng quy t\u1eafc m\u1ed9t c\u00e1ch linh ho\u1ea1t:<\/span><\/p>\n<p><b>use Illuminate\\Support\\Facades\\Validator;<\/b><\/p>\n<p><b>use Illuminate\\Validation\\Rule;<\/b><\/p>\n<p><b>\u00a0<\/b><\/p>\n<p><b>Validator::make($data, [<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0&#8216;avatar&#8217; =&gt; [<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;required&#8217;,<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Rule::dimensions()-&gt;maxWidth(1000)-&gt;maxHeight(500)-&gt;ratio(3 \/ 2),<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0],<\/b><\/p>\n<p><b>]);<\/b><\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>distinct\u00a0<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Khi x\u00e1c th\u1ef1c m\u1ea3ng, tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c kh\u00f4ng \u0111\u01b0\u1ee3c c\u00f3 b\u1ea5t k\u1ef3 gi\u00e1 tr\u1ecb tr\u00f9ng l\u1eb7p n\u00e0o:<\/span><\/p>\n<p><b>&#8216;foo.*.id&#8217; =&gt; &#8216;distinct&#8217;<\/b><\/p>\n<p><span style=\"font-weight: 400;\">M\u1eb7c \u0111\u1ecbnh, quy t\u1eafc distinct s\u1eed d\u1ee5ng so s\u00e1nh l\u1ecfng (loose). \u0110\u1ec3 s\u1eed d\u1ee5ng so s\u00e1nh ch\u1eb7t (strict), b\u1ea1n c\u00f3 th\u1ec3 th\u00eam tham s\u1ed1 strict v\u00e0o \u0111\u1ecbnh ngh\u0129a quy t\u1eafc x\u00e1c th\u1ef1c c\u1ee7a b\u1ea1n.<\/span><\/p>\n<p><b>&#8216;foo.*.id&#8217; =&gt; &#8216;distinct:strict&#8217;<\/b><\/p>\n<p><span style=\"font-weight: 400;\">B\u1ea1n c\u00f3 th\u1ec3 th\u00eam ignore_case v\u00e0o c\u00e1c \u0111\u1ed1i s\u1ed1 c\u1ee7a quy t\u1eafc x\u00e1c th\u1ef1c \u0111\u1ec3 n\u00f3 b\u1ecf qua s\u1ef1 kh\u00e1c bi\u1ec7t v\u1ec1 ch\u1eef hoa, ch\u1eef th\u01b0\u1eddng:<\/span><\/p>\n<p><b>&#8216;foo.*.id&#8217; =&gt; &#8216;distinct:ignore_case&#8217;<\/b><\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>doesnt_start_with<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c kh\u00f4ng \u0111\u01b0\u1ee3c b\u1eaft \u0111\u1ea7u b\u1eb1ng m\u1ed9t trong c\u00e1c gi\u00e1 tr\u1ecb \u0111\u00e3 cho.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>doesnt_end_with<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c kh\u00f4ng \u0111\u01b0\u1ee3c k\u1ebft th\u00fac b\u1eb1ng m\u1ed9t trong c\u00e1c gi\u00e1 tr\u1ecb \u0111\u00e3 cho.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>email<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i \u0111\u01b0\u1ee3c \u0111\u1ecbnh d\u1ea1ng nh\u01b0 m\u1ed9t \u0111\u1ecba ch\u1ec9 email h\u1ee3p l\u1ec7. Quy t\u1eafc n\u00e0y s\u1eed d\u1ee5ng g\u00f3i <\/span><a href=\"https:\/\/github.com\/egulias\/EmailValidator\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">egulias\/email-validator <\/span><\/a><span style=\"font-weight: 400;\">\u0111\u1ec3 x\u00e1c th\u1ef1c \u0111\u1ecba ch\u1ec9 email. Theo m\u1eb7c \u0111\u1ecbnh, b\u1ed9 ki\u1ec3m \u0111\u1ecbnh RFCValidation \u0111\u01b0\u1ee3c \u00e1p d\u1ee5ng, nh\u01b0ng b\u1ea1n c\u0169ng c\u00f3 th\u1ec3 \u00e1p d\u1ee5ng c\u00e1c ki\u1ec3u ki\u1ec3m \u0111\u1ecbnh kh\u00e1c:<\/span><\/p>\n<p><b>&#8217;email&#8217; =&gt; &#8217;email:rfc,dns&#8217;<\/b><\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>ends_with<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i k\u1ebft th\u00fac b\u1eb1ng m\u1ed9t trong c\u00e1c gi\u00e1 tr\u1ecb \u0111\u00e3 cho.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>enum<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Quy t\u1eafc Enum l\u00e0 m\u1ed9t quy t\u1eafc d\u1ef1a tr\u00ean l\u1edbp gi\u00fap x\u00e1c th\u1ef1c li\u1ec7u tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c c\u00f3 ch\u1ee9a gi\u00e1 tr\u1ecb enum h\u1ee3p l\u1ec7 hay kh\u00f4ng. Quy t\u1eafc enum ch\u1ec9 ch\u1ea5p nh\u1eadn t\u00ean c\u1ee7a enum l\u00e0m \u0111\u1ed1i s\u1ed1 duy nh\u1ea5t cho h\u00e0m kh\u1edfi t\u1ea1o. Khi x\u00e1c th\u1ef1c c\u00e1c gi\u00e1 tr\u1ecb c\u01a1 b\u1ea3n (primitive values), c\u1ea7n cung c\u1ea5p m\u1ed9t Enum c\u00f3 gi\u00e1 tr\u1ecb t\u01b0\u01a1ng \u1ee9ng cho quy t\u1eafc enum:<\/span><\/p>\n<p style=\"text-align: left;\"><b>use App\\Enums\\ServerStatus;<\/b><\/p>\n<p style=\"text-align: left;\"><b>use Illuminate\\Validation\\Rule;<\/b><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: left;\"><b>$request-&gt;validate([<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0\u00a0&#8216;status&#8217; =&gt; [Rule::enum(ServerStatus::class)],<\/b><\/p>\n<p style=\"text-align: left;\"><b>]);<\/b><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">C\u00e1c ph\u01b0\u01a1ng th\u1ee9c only v\u00e0 except c\u1ee7a quy t\u1eafc Enum c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 gi\u1edbi h\u1ea1n c\u00e1c tr\u01b0\u1eddng h\u1ee3p enum n\u00e0o \u0111\u01b0\u1ee3c coi l\u00e0 h\u1ee3p l\u1ec7:<\/span><\/p>\n<p style=\"text-align: left;\"><b>Rule::enum(ServerStatus::class)<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0\u00a0-&gt;only([ServerStatus::Pending, ServerStatus::Active]);<\/b><\/p>\n<p style=\"text-align: left;\"><b>Rule::enum(ServerStatus::class)<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0\u00a0-&gt;except([ServerStatus::Pending, ServerStatus::Active]);<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Ph\u01b0\u01a1ng th\u1ee9c when c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 \u0111i\u1ec1u ch\u1ec9nh quy t\u1eafc Enum theo \u0111i\u1ec1u ki\u1ec7n:<\/span><\/p>\n<p style=\"text-align: left;\"><b>use Illuminate\\Support\\Facades\\Auth;<\/b><\/p>\n<p style=\"text-align: left;\"><b>use Illuminate\\Validation\\Rule;<\/b><\/p>\n<p style=\"text-align: left;\"><b>Rule::enum(ServerStatus::class)<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0\u00a0-&gt;when(<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Auth::user()-&gt;isAdmin(),<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0fn ($rule) =&gt; $rule-&gt;only(&#8230;),<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0fn ($rule) =&gt; $rule-&gt;only(&#8230;),<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0\u00a0);<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>exclude<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c s\u1ebd b\u1ecb lo\u1ea1i tr\u1eeb kh\u1ecfi d\u1eef li\u1ec7u y\u00eau c\u1ea7u \u0111\u01b0\u1ee3c tr\u1ea3 v\u1ec1 b\u1edfi c\u00e1c ph\u01b0\u01a1ng th\u1ee9c validate v\u00e0 validated.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>exclude_if (anotherfield, value)<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c s\u1ebd b\u1ecb lo\u1ea1i tr\u1eeb kh\u1ecfi d\u1eef li\u1ec7u y\u00eau c\u1ea7u tr\u1ea3 v\u1ec1 b\u1edfi c\u00e1c ph\u01b0\u01a1ng th\u1ee9c validate v\u00e0 validated n\u1ebfu tr\u01b0\u1eddng anotherfield b\u1eb1ng v\u1edbi value.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">N\u1ebfu c\u1ea7n logic lo\u1ea1i tr\u1eeb theo \u0111i\u1ec1u ki\u1ec7n ph\u1ee9c t\u1ea1p, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng ph\u01b0\u01a1ng th\u1ee9c Rule::excludeIf. Ph\u01b0\u01a1ng th\u1ee9c n\u00e0y ch\u1ea5p nh\u1eadn m\u1ed9t gi\u00e1 tr\u1ecb boolean ho\u1eb7c m\u1ed9t closure (h\u00e0m \u1ea9n danh). Khi s\u1eed d\u1ee5ng closure, closure c\u1ea7n tr\u1ea3 v\u1ec1 true ho\u1eb7c false \u0111\u1ec3 ch\u1ec9 ra xem tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c c\u00f3 n\u00ean b\u1ecb lo\u1ea1i tr\u1eeb hay kh\u00f4ng:<\/span><\/p>\n<p style=\"text-align: left;\"><b>use Illuminate\\Support\\Facades\\Validator;<\/b><\/p>\n<p style=\"text-align: left;\"><b>use Illuminate\\Validation\\Rule;<\/b><\/p>\n<p style=\"text-align: left;\"><b>Validator::make($request-&gt;all(), [<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0\u00a0&#8216;role_id&#8217; =&gt; Rule::excludeIf($request-&gt;user()-&gt;is_admin),<\/b><\/p>\n<p style=\"text-align: left;\"><b>]);<\/b><\/p>\n<p style=\"text-align: left;\"><b>Validator::make($request-&gt;all(), [<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0\u00a0&#8216;role_id&#8217; =&gt; Rule::excludeIf(fn () =&gt; $request-&gt;user()-&gt;is_admin),<\/b><\/p>\n<p style=\"text-align: left;\"><b>]);<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>exclude_unless<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c s\u1ebd b\u1ecb lo\u1ea1i tr\u1eeb kh\u1ecfi d\u1eef li\u1ec7u y\u00eau c\u1ea7u \u0111\u01b0\u1ee3c tr\u1ea3 v\u1ec1 b\u1edfi c\u00e1c ph\u01b0\u01a1ng th\u1ee9c validate v\u00e0 validated tr\u1eeb khi tr\u01b0\u1eddng kh\u00e1c b\u1eb1ng v\u1edbi value.\u00a0<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">N\u1ebfu value l\u00e0 null (v\u00ed d\u1ee5: exclude_unless:name,null), tr\u01b0\u1eddng \u0111ang x\u00e1c th\u1ef1c s\u1ebd b\u1ecb lo\u1ea1i tr\u1eeb, tr\u1eeb khi tr\u01b0\u1eddng d\u00f9ng \u0111\u1ec3 so s\u00e1nh l\u00e0 null ho\u1eb7c kh\u00f4ng c\u00f3 trong d\u1eef li\u1ec7u y\u00eau c\u1ea7u.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>exclude_with<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c s\u1ebd b\u1ecb lo\u1ea1i tr\u1eeb kh\u1ecfi d\u1eef li\u1ec7u y\u00eau c\u1ea7u \u0111\u01b0\u1ee3c tr\u1ea3 v\u1ec1 b\u1edfi c\u00e1c ph\u01b0\u01a1ng th\u1ee9c validate v\u00e0 validated n\u1ebfu tr\u01b0\u1eddng kh\u00e1c anotherfield c\u00f3 gi\u00e1 tr\u1ecb.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>exclude_without<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Quy t\u1eafc exclude_without ho\u1ea1t \u0111\u1ed9ng ng\u01b0\u1ee3c l\u1ea1i v\u1edbi exclude_with. N\u00f3 lo\u1ea1i tr\u1eeb m\u1ed9t tr\u01b0\u1eddng kh\u1ecfi d\u1eef li\u1ec7u y\u00eau c\u1ea7u n\u1ebfu m\u1ed9t tr\u01b0\u1eddng kh\u00e1c kh\u00f4ng c\u00f3 gi\u00e1 tr\u1ecb.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>exists (table, column)<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i t\u1ed3n t\u1ea1i trong m\u1ed9t b\u1ea3ng c\u01a1 s\u1edf d\u1eef li\u1ec7u \u0111\u00e3 cho.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">C\u00e1ch s\u1eed d\u1ee5ng c\u01a1 b\u1ea3n c\u1ee7a quy t\u1eafc exists:<\/span><\/p>\n<p style=\"text-align: left;\"><b>&#8216;state&#8217; =&gt; &#8216;exists:states&#8217;<\/b><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">N\u1ebfu t\u00f9y ch\u1ecdn column kh\u00f4ng \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh, t\u00ean tr\u01b0\u1eddng s\u1ebd \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng. V\u00ec v\u1eady, trong tr\u01b0\u1eddng h\u1ee3p n\u00e0y, quy t\u1eafc s\u1ebd x\u00e1c th\u1ef1c r\u1eb1ng b\u1ea3ng c\u01a1 s\u1edf d\u1eef li\u1ec7u states c\u00f3 ch\u1ee9a m\u1ed9t b\u1ea3n ghi v\u1edbi gi\u00e1 tr\u1ecb c\u1ed9t state kh\u1edbp v\u1edbi gi\u00e1 tr\u1ecb thu\u1ed9c t\u00ednh state trong y\u00eau c\u1ea7u.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>extensions<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">T\u1ec7p tin \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 ph\u1ea7n m\u1edf r\u1ed9ng do ng\u01b0\u1eddi d\u00f9ng ch\u1ec9 \u0111\u1ecbnh t\u01b0\u01a1ng \u1ee9ng v\u1edbi m\u1ed9t trong c\u00e1c ph\u1ea7n m\u1edf r\u1ed9ng \u0111\u01b0\u1ee3c li\u1ec7t k\u00ea:<\/span><\/p>\n<p style=\"text-align: left;\"><b>&#8216;photo&#8217; =&gt; [&#8216;required&#8217;, &#8216;extensions:jpg,png&#8217;],<\/b><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">B\u1ea1n kh\u00f4ng n\u00ean d\u1ef1a v\u00e0o vi\u1ec7c x\u00e1c th\u1ef1c m\u1ed9t t\u1ec7p tin ch\u1ec9 b\u1eb1ng ph\u1ea7n m\u1edf r\u1ed9ng do ng\u01b0\u1eddi d\u00f9ng ch\u1ec9 \u0111\u1ecbnh, m\u00e0 n\u00ean lu\u00f4n lu\u00f4n k\u1ebft h\u1ee3p quy t\u1eafc n\u00e0y v\u1edbi quy t\u1eafc mimes ho\u1eb7c mimetypes.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>file<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t t\u1ec7p tin \u0111\u00e3 t\u1ea3i l\u00ean th\u00e0nh c\u00f4ng.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>filled<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c kh\u00f4ng \u0111\u01b0\u1ee3c \u0111\u1ec3 tr\u1ed1ng khi n\u00f3 c\u00f3 m\u1eb7t.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>gt<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u1edbn h\u01a1n gi\u00e1 tr\u1ecb tr\u01b0\u1eddng ho\u1eb7c gi\u00e1 tr\u1ecb \u0111\u00e3 cho. Hai tr\u01b0\u1eddng ph\u1ea3i c\u00f9ng lo\u1ea1i d\u1eef li\u1ec7u. Chu\u1ed7i, s\u1ed1, m\u1ea3ng v\u00e0 t\u1ec7p tin \u0111\u01b0\u1ee3c \u0111\u00e1nh gi\u00e1 b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng c\u00e1c quy \u01b0\u1edbc t\u01b0\u01a1ng t\u1ef1 nh\u01b0 quy t\u1eafc size.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>gte<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u1edbn h\u01a1n ho\u1eb7c b\u1eb1ng gi\u00e1 tr\u1ecb tr\u01b0\u1eddng ho\u1eb7c gi\u00e1 tr\u1ecb \u0111\u00e3 cho. Hai tr\u01b0\u1eddng ph\u1ea3i c\u00f9ng lo\u1ea1i d\u1eef li\u1ec7u. Chu\u1ed7i, s\u1ed1, m\u1ea3ng v\u00e0 t\u1ec7p tin \u0111\u01b0\u1ee3c \u0111\u00e1nh gi\u00e1 b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng c\u00e1c quy \u01b0\u1edbc t\u01b0\u01a1ng t\u1ef1 nh\u01b0 quy t\u1eafc size.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>hex_color<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb c\u1ee7a tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t m\u00e3 m\u00e0u h\u1ee3p l\u1ec7 theo \u0111\u1ecbnh d\u1ea1ng HEX.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>image<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">File \u0111\u01b0\u1ee3c upload ph\u1ea3i l\u00e0 m\u1ed9t h\u00ecnh \u1ea3nh (jpg, jpeg, png, bmp, gif, svg, ho\u1eb7c webp).<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>in:foo,bar,&#8230;<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i n\u1eb1m trong danh s\u00e1ch c\u00e1c gi\u00e1 tr\u1ecb \u0111\u00e3 cho. V\u00ec quy t\u1eafc n\u00e0y th\u01b0\u1eddng y\u00eau c\u1ea7u b\u1ea1n n\u1ed1i c\u00e1c ph\u1ea7n t\u1eed m\u1ea3ng l\u1ea1i v\u1edbi nhau, n\u00ean b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng ph\u01b0\u01a1ng th\u1ee9c Rule::in \u0111\u1ec3 x\u00e2y d\u1ef1ng quy t\u1eafc m\u1ed9t c\u00e1ch tr\u00f4i ch\u1ea3y:<\/span><\/p>\n<p style=\"text-align: left;\"><b>use Illuminate\\Support\\Facades\\Validator;<\/b><\/p>\n<p style=\"text-align: left;\"><b>use Illuminate\\Validation\\Rule;<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0<\/b><\/p>\n<p style=\"text-align: left;\"><b>Validator::make($data, [<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0&#8216;zones&#8217; =&gt; [<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;required&#8217;,<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Rule::in([&#8216;first-zone&#8217;, &#8216;second-zone&#8217;]),<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0],<\/b><\/p>\n<p style=\"text-align: left;\"><b>]);<\/b><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Khi k\u1ebft h\u1ee3p quy t\u1eafc in v\u1edbi quy t\u1eafc array, m\u1ed7i gi\u00e1 tr\u1ecb trong m\u1ea3ng \u0111\u1ea7u v\u00e0o ph\u1ea3i c\u00f3 m\u1eb7t trong danh s\u00e1ch c\u00e1c gi\u00e1 tr\u1ecb \u0111\u01b0\u1ee3c cung c\u1ea5p cho quy t\u1eafc in.\u00a0<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>in_array:anotherfield<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i t\u1ed3n t\u1ea1i trong c\u00e1c gi\u00e1 tr\u1ecb c\u1ee7a tr\u01b0\u1eddng anotherfield.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>integer<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t s\u1ed1 nguy\u00ean.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>ip<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t \u0111\u1ecba ch\u1ec9 IP.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>ipv4<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t \u0111\u1ecba ch\u1ec9 IPv4.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>ipv6<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t \u0111\u1ecba ch\u1ec9 IPv6.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>json<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t chu\u1ed7i JSON h\u1ee3p l\u1ec7.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>lt<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i nh\u1ecf h\u01a1n tr\u01b0\u1eddng \u0111\u00e3 cho. Hai tr\u01b0\u1eddng ph\u1ea3i c\u00f9ng lo\u1ea1i d\u1eef li\u1ec7u. Chu\u1ed7i, s\u1ed1, m\u1ea3ng v\u00e0 t\u1ec7p tin \u0111\u01b0\u1ee3c \u0111\u00e1nh gi\u00e1 theo c\u00e1c quy \u01b0\u1edbc t\u01b0\u01a1ng t\u1ef1 nh\u01b0 quy t\u1eafc size.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>lte<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i nh\u1ecf h\u01a1n ho\u1eb7c b\u1eb1ng tr\u01b0\u1eddng \u0111\u00e3 cho. Hai tr\u01b0\u1eddng ph\u1ea3i c\u00f9ng lo\u1ea1i d\u1eef li\u1ec7u. Chu\u1ed7i, s\u1ed1, m\u1ea3ng v\u00e0 t\u1ec7p tin \u0111\u01b0\u1ee3c \u0111\u00e1nh gi\u00e1 theo c\u00e1c quy \u01b0\u1edbc t\u01b0\u01a1ng t\u1ef1 nh\u01b0 quy t\u1eafc size.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>lowercase<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 ch\u1eef th\u01b0\u1eddng.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>list<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t m\u1ea3ng v\u00e0 l\u00e0 m\u1ed9t danh s\u00e1ch. M\u1ed9t m\u1ea3ng \u0111\u01b0\u1ee3c coi l\u00e0 danh s\u00e1ch n\u1ebfu c\u00e1c kh\u00f3a c\u1ee7a n\u00f3 bao g\u1ed3m c\u00e1c s\u1ed1 li\u00ean ti\u1ebfp t\u1eeb 0 \u0111\u1ebfn count($array) &#8211; 1.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>mac_address<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t \u0111\u1ecba ch\u1ec9 MAC.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>max<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i nh\u1ecf h\u01a1n ho\u1eb7c b\u1eb1ng gi\u00e1 tr\u1ecb t\u1ed1i \u0111a. Chu\u1ed7i, s\u1ed1, m\u1ea3ng v\u00e0 t\u1ec7p tin \u0111\u01b0\u1ee3c \u0111\u00e1nh gi\u00e1 theo c\u00f9ng m\u1ed9t c\u00e1ch nh\u01b0 quy t\u1eafc size.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>max_digits:value<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">S\u1ed1 nguy\u00ean \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 \u0111\u1ed9 d\u00e0i t\u1ed1i \u0111a l\u00e0 gi\u00e1 tr\u1ecb (value) \u0111\u00e3 cho.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>mimetypes:text\/plain,&#8230;<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">T\u1ec7p tin \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i kh\u1edbp v\u1edbi m\u1ed9t trong c\u00e1c lo\u1ea1i MIME \u0111\u00e3 cho:<\/span><\/p>\n<p style=\"text-align: left;\"><b>&#8216;video&#8217; =&gt; &#8216;mimetypes:video\/avi,video\/mpeg,video\/quicktime&#8217;<\/b><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">\u0110\u1ec3 x\u00e1c \u0111\u1ecbnh lo\u1ea1i MIME c\u1ee7a t\u1ec7p tin \u0111\u00e3 t\u1ea3i l\u00ean, n\u1ed9i dung c\u1ee7a t\u1ec7p s\u1ebd \u0111\u01b0\u1ee3c \u0111\u1ecdc v\u00e0 framework s\u1ebd c\u1ed1 g\u1eafng \u0111o\u00e1n lo\u1ea1i MIME, c\u00f3 th\u1ec3 kh\u00e1c v\u1edbi lo\u1ea1i MIME do kh\u00e1ch h\u00e0ng cung c\u1ea5p.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>mimes:foo,bar,&#8230;<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">T\u1ec7p tin \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 lo\u1ea1i MIME t\u01b0\u01a1ng \u1ee9ng v\u1edbi m\u1ed9t trong c\u00e1c ph\u1ea7n m\u1edf r\u1ed9ng \u0111\u00e3 li\u1ec7t k\u00ea:<\/span><\/p>\n<p style=\"text-align: left;\"><b>&#8216;photo&#8217; =&gt; &#8216;mimes:jpg,bmp,png&#8217;<\/b><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">M\u1eb7c d\u00f9 b\u1ea1n ch\u1ec9 c\u1ea7n ch\u1ec9 \u0111\u1ecbnh c\u00e1c ph\u1ea7n m\u1edf r\u1ed9ng, quy t\u1eafc n\u00e0y th\u1ef1c t\u1ebf x\u00e1c th\u1ef1c lo\u1ea1i MIME c\u1ee7a t\u1ec7p b\u1eb1ng c\u00e1ch \u0111\u1ecdc n\u1ed9i dung c\u1ee7a t\u1ec7p v\u00e0 \u0111o\u00e1n lo\u1ea1i MIME c\u1ee7a n\u00f3. Xem <\/span><a href=\"https:\/\/svn.apache.org\/repos\/asf\/httpd\/httpd\/trunk\/docs\/conf\/mime.types\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">danh s\u00e1ch \u0111\u1ea7y \u0111\u1ee7<\/span><\/a><span style=\"font-weight: 400;\"> c\u00e1c MIME types v\u00e0 c\u00e1c ph\u1ea7n m\u1edf r\u1ed9ng t\u01b0\u01a1ng \u1ee9ng c\u1ee7a ch\u00fang.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>min:value<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb c\u1ee7a tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 gi\u00e1 tr\u1ecb t\u1ed1i thi\u1ec3u l\u00e0 value. Chu\u1ed7i, s\u1ed1, m\u1ea3ng v\u00e0 t\u1ec7p tin \u0111\u01b0\u1ee3c \u0111\u00e1nh gi\u00e1 theo c\u00f9ng m\u1ed9t c\u00e1ch nh\u01b0 quy t\u1eafc size.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>min_digits:value<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">S\u1ed1 nguy\u00ean \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 \u0111\u1ed9 d\u00e0i t\u1ed1i thi\u1ec3u l\u00e0 gi\u00e1 tr\u1ecb \u0111\u00e3 cho.<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>multiple_of:value<\/b><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 b\u1ed9i s\u1ed1 c\u1ee7a gi\u00e1 tr\u1ecb \u0111\u00e3 cho.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>missing<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c kh\u00f4ng \u0111\u01b0\u1ee3c c\u00f3 m\u1eb7t trong d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o.<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>missing_if:anotherfield,value,&#8230;<\/b><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c kh\u00f4ng \u0111\u01b0\u1ee3c c\u00f3 m\u1eb7t n\u1ebfu tr\u01b0\u1eddng anotherfield b\u1eb1ng v\u1edbi b\u1ea5t k\u1ef3 gi\u00e1 tr\u1ecb (value) n\u00e0o.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>missing_unless:anotherfield,value<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c kh\u00f4ng \u0111\u01b0\u1ee3c c\u00f3 m\u1eb7t tr\u1eeb khi tr\u01b0\u1eddng anotherfield b\u1eb1ng v\u1edbi b\u1ea5t k\u1ef3 gi\u00e1 tr\u1ecb (value) n\u00e0o.<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>missing_with:foo,bar,&#8230;<\/b><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ch\u1ec9 \u0111\u01b0\u1ee3c ph\u00e9p kh\u00f4ng c\u00f3 m\u1eb7t n\u1ebfu b\u1ea5t k\u1ef3 tr\u01b0\u1eddng n\u00e0o kh\u00e1c \u0111\u01b0\u1ee3c li\u1ec7t k\u00ea c\u00f3 m\u1eb7t.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>missing_with_all:foo,bar,&#8230;<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ch\u1ec9 \u0111\u01b0\u1ee3c ph\u00e9p <\/span><b>kh\u00f4ng c\u00f3 m\u1eb7t<\/b><span style=\"font-weight: 400;\"> n\u1ebfu <\/span><b>t\u1ea5t c\u1ea3<\/b><span style=\"font-weight: 400;\"> c\u00e1c tr\u01b0\u1eddng kh\u00e1c \u0111\u01b0\u1ee3c li\u1ec7t k\u00ea <\/span><b>\u0111\u1ec1u c\u00f3 m\u1eb7t<\/b><span style=\"font-weight: 400;\">.<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>not_in:foo,bar,&#8230;<\/b><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c kh\u00f4ng \u0111\u01b0\u1ee3c n\u1eb1m trong danh s\u00e1ch c\u00e1c gi\u00e1 tr\u1ecb \u0111\u00e3 cho. Ph\u01b0\u01a1ng th\u1ee9c Rule::notIn c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 x\u00e2y d\u1ef1ng quy t\u1eafc m\u1ed9t c\u00e1ch tr\u00f4i ch\u1ea3y:<\/span><\/p>\n<p style=\"text-align: left;\"><b>use Illuminate\\Validation\\Rule;<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0<\/b><\/p>\n<p style=\"text-align: left;\"><b>Validator::make($data, [<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0&#8216;toppings&#8217; =&gt; [<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;required&#8217;,<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Rule::notIn([&#8216;sprinkles&#8217;, &#8216;cherries&#8217;]),<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0],<\/b><\/p>\n<p style=\"text-align: left;\"><b>]);<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>not_regex:pattern<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c kh\u00f4ng \u0111\u01b0\u1ee3c kh\u1edbp v\u1edbi bi\u1ec3u th\u1ee9c ch\u00ednh quy \u0111\u00e3 cho.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Quy t\u1eafc n\u00e0y s\u1eed d\u1ee5ng h\u00e0m preg_match c\u1ee7a PHP. Bi\u1ec3u th\u1ee9c pattern \u0111\u01b0\u1ee3c cung c\u1ea5p c\u1ea7n tu\u00e2n theo \u0111\u1ecbnh d\u1ea1ng y\u00eau c\u1ea7u c\u1ee7a preg_match v\u00e0 bao g\u1ed3m c\u1ea3 d\u1ea5u ph\u00e2n c\u00e1ch h\u1ee3p l\u1ec7. <\/span><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><\/p>\n<p><b>&#8217;email&#8217; =&gt; &#8216;not_regex:\/^.+$\/i&#8217;.<\/b><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>nullable<\/b><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c c\u00f3 th\u1ec3 l\u00e0 null.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>numeric<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 s\u1ed1.<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>present<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i t\u1ed3n t\u1ea1i trong d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>present_if:anotherfield,value,&#8230;<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 m\u1eb7t n\u1ebfu tr\u01b0\u1eddng anotherfield b\u1eb1ng v\u1edbi b\u1ea5t k\u1ef3 gi\u00e1 tr\u1ecb (value) n\u00e0o.<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>present_unless:anotherfield,value<\/b><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 m\u1eb7t tr\u1eeb khi tr\u01b0\u1eddng anotherfield b\u1eb1ng v\u1edbi b\u1ea5t k\u1ef3 gi\u00e1 tr\u1ecb n\u00e0o.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>present_with:foo,bar,&#8230;<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 m\u1eb7t ch\u1ec9 khi b\u1ea5t k\u1ef3 tr\u01b0\u1eddng n\u00e0o kh\u00e1c \u0111\u00e3 \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh c\u00f3 m\u1eb7t.<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>present_with_all:foo,bar,..<\/b><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 m\u1eb7t ch\u1ec9 khi t\u1ea5t c\u1ea3 c\u00e1c tr\u01b0\u1eddng kh\u00e1c \u0111\u00e3 \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh c\u00f3 m\u1eb7t.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>prohibited<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i kh\u00f4ng c\u00f3 m\u1eb7t ho\u1eb7c tr\u1ed1ng. M\u1ed9t tr\u01b0\u1eddng \u0111\u01b0\u1ee3c coi l\u00e0 &#8220;tr\u1ed1ng&#8221; n\u1ebfu n\u00f3 \u0111\u00e1p \u1ee9ng m\u1ed9t trong c\u00e1c ti\u00eau ch\u00ed sau:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 null.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 m\u1ed9t chu\u1ed7i r\u1ed7ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 m\u1ed9t m\u1ea3ng r\u1ed7ng ho\u1eb7c \u0111\u1ed1i t\u01b0\u1ee3ng Countable r\u1ed7ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 m\u1ed9t t\u1ec7p t\u1ea3i l\u00ean v\u1edbi \u0111\u01b0\u1eddng d\u1eabn r\u1ed7ng.<\/span><\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>prohibited_if:anotherfield,value,&#8230;<\/b><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i kh\u00f4ng c\u00f3 m\u1eb7t ho\u1eb7c tr\u1ed1ng n\u1ebfu tr\u01b0\u1eddng anotherfield b\u1eb1ng v\u1edbi b\u1ea5t k\u1ef3 gi\u00e1 tr\u1ecb (value) n\u00e0o. M\u1ed9t tr\u01b0\u1eddng \u0111\u01b0\u1ee3c coi l\u00e0 &#8220;tr\u1ed1ng&#8221; n\u1ebfu n\u00f3 \u0111\u00e1p \u1ee9ng m\u1ed9t trong c\u00e1c ti\u00eau ch\u00ed sau:<\/span><\/p>\n<ul style=\"text-align: left;\">\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 null.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 m\u1ed9t chu\u1ed7i r\u1ed7ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 m\u1ed9t m\u1ea3ng r\u1ed7ng ho\u1eb7c \u0111\u1ed1i t\u01b0\u1ee3ng Countable r\u1ed7ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 m\u1ed9t t\u1ec7p t\u1ea3i l\u00ean v\u1edbi \u0111\u01b0\u1eddng d\u1eabn r\u1ed7ng.<\/span><\/li>\n<\/ul>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">N\u1ebfu c\u1ea7n logic lo\u1ea1i tr\u1eeb theo \u0111i\u1ec1u ki\u1ec7n ph\u1ee9c t\u1ea1p, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng ph\u01b0\u01a1ng th\u1ee9c Rule::prohibitedIf. Ph\u01b0\u01a1ng th\u1ee9c n\u00e0y ch\u1ea5p nh\u1eadn m\u1ed9t gi\u00e1 tr\u1ecb boolean ho\u1eb7c m\u1ed9t closure (h\u00e0m \u1ea9n danh). Khi s\u1eed d\u1ee5ng closure, closure c\u1ea7n tr\u1ea3 v\u1ec1 true ho\u1eb7c false \u0111\u1ec3 b\u00e1o hi\u1ec7u c\u00f3 n\u00ean lo\u1ea1i tr\u1eeb tr\u01b0\u1eddng c\u1ea7n ki\u1ec3m \u0111\u1ecbnh hay kh\u00f4ng:<\/span><\/p>\n<p style=\"text-align: left;\"><b>use Illuminate\\Support\\Facades\\Validator;<\/b><\/p>\n<p style=\"text-align: left;\"><b>use Illuminate\\Validation\\Rule;<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0<\/b><\/p>\n<p style=\"text-align: left;\"><b>Validator::make($request-&gt;all(), [<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0&#8216;role_id&#8217; =&gt; Rule::prohibitedIf($request-&gt;user()-&gt;is_admin),<\/b><\/p>\n<p style=\"text-align: left;\"><b>]);<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0<\/b><\/p>\n<p style=\"text-align: left;\"><b>Validator::make($request-&gt;all(), [<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0&#8216;role_id&#8217; =&gt; Rule::prohibitedIf(fn () =&gt; $request-&gt;user()-&gt;is_admin),<\/b><\/p>\n<p style=\"text-align: left;\"><b>]);<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>prohibited_unless:anotherfield,value,&#8230;<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i kh\u00f4ng c\u00f3 m\u1eb7t ho\u1eb7c tr\u1ed1ng tr\u1eeb khi tr\u01b0\u1eddng anotherfield b\u1eb1ng v\u1edbi b\u1ea5t k\u1ef3 gi\u00e1 tr\u1ecb n\u00e0o. M\u1ed9t tr\u01b0\u1eddng \u0111\u01b0\u1ee3c coi l\u00e0 &#8220;tr\u1ed1ng&#8221; n\u1ebfu n\u00f3 \u0111\u00e1p \u1ee9ng m\u1ed9t trong c\u00e1c ti\u00eau ch\u00ed sau:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 null.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 m\u1ed9t chu\u1ed7i r\u1ed7ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 m\u1ed9t m\u1ea3ng r\u1ed7ng ho\u1eb7c \u0111\u1ed1i t\u01b0\u1ee3ng Countable r\u1ed7ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 m\u1ed9t t\u1ec7p t\u1ea3i l\u00ean v\u1edbi \u0111\u01b0\u1eddng d\u1eabn r\u1ed7ng.<\/span><\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>prohibits:anotherfield,&#8230;<\/b><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">N\u1ebfu tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c kh\u00f4ng thi\u1ebfu ho\u1eb7c tr\u1ed1ng, t\u1ea5t c\u1ea3 c\u00e1c tr\u01b0\u1eddng trong anotherfield ph\u1ea3i thi\u1ebfu ho\u1eb7c tr\u1ed1ng. M\u1ed9t tr\u01b0\u1eddng \u0111\u01b0\u1ee3c coi l\u00e0 &#8220;tr\u1ed1ng&#8221; n\u1ebfu n\u00f3 \u0111\u00e1p \u1ee9ng m\u1ed9t trong c\u00e1c ti\u00eau ch\u00ed sau:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400; text-align: left;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 null.<\/span><\/li>\n<li style=\"font-weight: 400; text-align: left;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 m\u1ed9t chu\u1ed7i r\u1ed7ng.<\/span><\/li>\n<li style=\"font-weight: 400; text-align: left;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 m\u1ed9t m\u1ea3ng r\u1ed7ng ho\u1eb7c \u0111\u1ed1i t\u01b0\u1ee3ng Countable r\u1ed7ng.<\/span><\/li>\n<li style=\"font-weight: 400; text-align: left;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 m\u1ed9t t\u1ec7p t\u1ea3i l\u00ean v\u1edbi \u0111\u01b0\u1eddng d\u1eabn r\u1ed7ng.<\/span><\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>regex:pattern<\/b><\/p>\n<\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i kh\u1edbp v\u1edbi bi\u1ec3u th\u1ee9c ch\u00ednh quy \u0111\u00e3 cho.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Quy t\u1eafc n\u00e0y s\u1eed d\u1ee5ng h\u00e0m preg_match c\u1ee7a PHP. Bi\u1ec3u th\u1ee9c pattern \u0111\u01b0\u1ee3c cung c\u1ea5p c\u1ea7n tu\u00e2n theo \u0111\u1ecbnh d\u1ea1ng y\u00eau c\u1ea7u b\u1edfi preg_match v\u00e0 do \u0111\u00f3 c\u0169ng bao g\u1ed3m c\u1ea3 d\u1ea5u ph\u00e2n c\u00e1ch h\u1ee3p l\u1ec7. V\u00ed d\u1ee5:\u00a0<\/span><\/p>\n<p style=\"text-align: left;\"><b>&#8217;email&#8217; =&gt; &#8216;regex:\/^.+@.+$\/i&#8217; (ki\u1ec3m tra email).<\/b><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">L\u01b0u \u00fd: Khi s\u1eed d\u1ee5ng c\u00e1c quy t\u1eafc regex (ki\u1ec3m tra theo bi\u1ec3u th\u1ee9c ch\u00ednh quy) v\u00e0 not_regex (kh\u00f4ng kh\u1edbp v\u1edbi bi\u1ec3u th\u1ee9c ch\u00ednh quy), b\u1ea1n c\u00f3 th\u1ec3 c\u1ea7n ph\u1ea3i ch\u1ec9 \u0111\u1ecbnh c\u00e1c quy t\u1eafc trong m\u1ed9t m\u1ea3ng thay v\u00ec s\u1eed d\u1ee5ng c\u00e1c d\u1ea5u ph\u00e2n c\u00e1ch |, \u0111\u1eb7c bi\u1ec7t n\u1ebfu bi\u1ec3u th\u1ee9c ch\u00ednh quy ch\u1ee9a k\u00fd t\u1ef1 |.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>required<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 m\u1eb7t trong d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o v\u00e0 kh\u00f4ng \u0111\u01b0\u1ee3c tr\u1ed1ng. M\u1ed9t tr\u01b0\u1eddng \u0111\u01b0\u1ee3c coi l\u00e0 &#8220;tr\u1ed1ng&#8221; n\u1ebfu n\u00f3 \u0111\u00e1p \u1ee9ng m\u1ed9t trong c\u00e1c ti\u00eau ch\u00ed sau:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 null.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 m\u1ed9t chu\u1ed7i r\u1ed7ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 m\u1ed9t m\u1ea3ng r\u1ed7ng ho\u1eb7c \u0111\u1ed1i t\u01b0\u1ee3ng Countable r\u1ed7ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb l\u00e0 m\u1ed9t t\u1ec7p t\u1ea3i l\u00ean v\u1edbi \u0111\u01b0\u1eddng d\u1eabn r\u1ed7ng.<\/span><\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>required_if:anotherfield,value,&#8230;<\/b><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 m\u1eb7t v\u00e0 kh\u00f4ng \u0111\u01b0\u1ee3c tr\u1ed1ng n\u1ebfu tr\u01b0\u1eddng anotherfield b\u1eb1ng v\u1edbi b\u1ea5t k\u1ef3 gi\u00e1 tr\u1ecb (value) n\u00e0o.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">N\u1ebfu b\u1ea1n mu\u1ed1n t\u1ea1o m\u1ed9t \u0111i\u1ec1u ki\u1ec7n ph\u1ee9c t\u1ea1p h\u01a1n cho quy t\u1eafc required_if, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng ph\u01b0\u01a1ng th\u1ee9c Rule::requiredIf. Ph\u01b0\u01a1ng th\u1ee9c n\u00e0y ch\u1ea5p nh\u1eadn m\u1ed9t boolean ho\u1eb7c m\u1ed9t closure. Khi \u0111\u01b0\u1ee3c cung c\u1ea5p m\u1ed9t closure, closure n\u00e0y s\u1ebd tr\u1ea3 v\u1ec1 true ho\u1eb7c false \u0111\u1ec3 x\u00e1c \u0111\u1ecbnh xem tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c c\u00f3 b\u1eaft bu\u1ed9c hay kh\u00f4ng:<\/span><\/p>\n<p style=\"text-align: left;\"><b>use Illuminate\\Support\\Facades\\Validator;<\/b><\/p>\n<p style=\"text-align: left;\"><b>use Illuminate\\Validation\\Rule;<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0<\/b><\/p>\n<p style=\"text-align: left;\"><b>Validator::make($request-&gt;all(), [<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0\u00a0&#8216;role_id&#8217; =&gt; Rule::requiredIf($request-&gt;user()-&gt;is_admin),<\/b><\/p>\n<p style=\"text-align: left;\"><b>]);<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0<\/b><\/p>\n<p style=\"text-align: left;\"><b>Validator::make($request-&gt;all(), [<\/b><\/p>\n<p style=\"text-align: left;\"><b>\u00a0\u00a0\u00a0\u00a0&#8216;role_id&#8217; =&gt; Rule::requiredIf(fn () =&gt; $request-&gt;user()-&gt;is_admin),<\/b><\/p>\n<p style=\"text-align: left;\"><b>]);<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>required_if_accepted:anotherfield,&#8230;<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 m\u1eb7t v\u00e0 kh\u00f4ng \u0111\u01b0\u1ee3c tr\u1ed1ng n\u1ebfu tr\u01b0\u1eddng anotherfield c\u00f3 gi\u00e1 tr\u1ecb l\u00e0 &#8220;yes&#8221;, &#8220;on&#8221;, 1, &#8220;1&#8221;, true, ho\u1eb7c &#8220;true&#8221;.<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>required_if_declined:anotherfield,&#8230;<\/b><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 m\u1eb7t v\u00e0 kh\u00f4ng \u0111\u01b0\u1ee3c tr\u1ed1ng n\u1ebfu tr\u01b0\u1eddng anotherfield b\u1eb1ng v\u1edbi &#8220;no&#8221;, &#8220;off&#8221;, 0, &#8220;0&#8221;, false, ho\u1eb7c &#8220;false&#8221;.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>required_unless:anotherfield,value,&#8230;<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 m\u1eb7t v\u00e0 kh\u00f4ng \u0111\u01b0\u1ee3c tr\u1ed1ng tr\u1eeb khi tr\u01b0\u1eddng anotherfield b\u1eb1ng v\u1edbi b\u1ea5t k\u1ef3 gi\u00e1 tr\u1ecb n\u00e0o.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u0110i\u1ec1u n\u00e0y c\u0169ng c\u00f3 ngh\u0129a l\u00e0 tr\u01b0\u1eddng anotherfield ph\u1ea3i c\u00f3 m\u1eb7t trong d\u1eef li\u1ec7u y\u00eau c\u1ea7u tr\u1eeb khi gi\u00e1 tr\u1ecb l\u00e0 null. N\u1ebfu gi\u00e1 tr\u1ecb l\u00e0 null (required_unless:name,null), tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c s\u1ebd b\u1eaft bu\u1ed9c tr\u1eeb khi tr\u01b0\u1eddng so s\u00e1nh l\u00e0 null ho\u1eb7c tr\u01b0\u1eddng so s\u00e1nh kh\u00f4ng c\u00f3 m\u1eb7t trong d\u1eef li\u1ec7u y\u00eau c\u1ea7u.<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>required_with:foo,bar,&#8230;<\/b><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 m\u1eb7t v\u00e0 kh\u00f4ng \u0111\u01b0\u1ee3c tr\u1ed1ng ch\u1ec9 khi b\u1ea5t k\u1ef3 tr\u01b0\u1eddng n\u00e0o kh\u00e1c \u0111\u00e3 \u0111\u01b0\u1ee3c li\u1ec7t k\u00ea c\u00f3 m\u1eb7t v\u00e0 kh\u00f4ng tr\u1ed1ng.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>required_with_all:foo,bar,&#8230;<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 m\u1eb7t v\u00e0 kh\u00f4ng \u0111\u01b0\u1ee3c tr\u1ed1ng ch\u1ec9 khi t\u1ea5t c\u1ea3 c\u00e1c tr\u01b0\u1eddng kh\u00e1c \u0111\u00e3 \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh \u0111\u1ec1u c\u00f3 m\u1eb7t v\u00e0 kh\u00f4ng tr\u1ed1ng.<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>required_without:foo,bar,&#8230;<\/b><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 m\u1eb7t v\u00e0 kh\u00f4ng \u0111\u01b0\u1ee3c tr\u1ed1ng ch\u1ec9 khi b\u1ea5t k\u1ef3 tr\u01b0\u1eddng n\u00e0o kh\u00e1c \u0111\u00e3 \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh tr\u1ed1ng ho\u1eb7c kh\u00f4ng c\u00f3 m\u1eb7t.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>required_without_all:foo,bar,&#8230;<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 m\u1eb7t v\u00e0 kh\u00f4ng \u0111\u01b0\u1ee3c tr\u1ed1ng ch\u1ec9 khi t\u1ea5t c\u1ea3 c\u00e1c tr\u01b0\u1eddng kh\u00e1c \u0111\u00e3 \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh \u0111\u1ec1u tr\u1ed1ng ho\u1eb7c kh\u00f4ng c\u00f3 m\u1eb7t.<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>required_array_keys:foo,bar,&#8230;<\/b><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t m\u1ea3ng v\u00e0 ph\u1ea3i ch\u1ee9a \u00edt nh\u1ea5t c\u00e1c kh\u00f3a \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>same:field<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb c\u1ee7a tr\u01b0\u1eddng \u0111ang x\u00e1c th\u1ef1c ph\u1ea3i gi\u1ed1ng h\u1ec7t v\u1edbi gi\u00e1 tr\u1ecb c\u1ee7a tr\u01b0\u1eddng field.<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>size:value<\/b><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i c\u00f3 k\u00edch th\u01b0\u1edbc kh\u1edbp v\u1edbi value \u0111\u00e3 cho.\u00a0<\/span><\/p>\n<ul style=\"text-align: left;\">\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u0110\u1ed1i v\u1edbi d\u1eef li\u1ec7u chu\u1ed7i, gi\u00e1 tr\u1ecb t\u01b0\u01a1ng \u1ee9ng v\u1edbi s\u1ed1 l\u01b0\u1ee3ng k\u00fd t\u1ef1.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u0110\u1ed1i v\u1edbi d\u1eef li\u1ec7u s\u1ed1, gi\u00e1 tr\u1ecb t\u01b0\u01a1ng \u1ee9ng v\u1edbi m\u1ed9t gi\u00e1 tr\u1ecb s\u1ed1 nguy\u00ean \u0111\u00e3 cho (thu\u1ed9c t\u00ednh c\u0169ng ph\u1ea3i c\u00f3 quy t\u1eafc numeric ho\u1eb7c integer).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u0110\u1ed1i v\u1edbi m\u1ea3ng, k\u00edch th\u01b0\u1edbc t\u01b0\u01a1ng \u1ee9ng v\u1edbi s\u1ed1 l\u01b0\u1ee3ng ph\u1ea7n t\u1eed trong m\u1ea3ng.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u0110\u1ed1i v\u1edbi t\u1ec7p, k\u00edch th\u01b0\u1edbc t\u01b0\u01a1ng \u1ee9ng v\u1edbi k\u00edch th\u01b0\u1edbc t\u1ec7p t\u00ednh b\u1eb1ng kilobyte.\u00a0<\/span><\/li>\n<\/ul>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">H\u00e3y xem m\u1ed9t s\u1ed1 v\u00ed d\u1ee5:<\/span><\/p>\n<p style=\"text-align: left;\"><b>\/\/ X\u00e1c th\u1ef1c r\u1eb1ng m\u1ed9t chu\u1ed7i c\u00f3 ch\u00ednh x\u00e1c 12 k\u00fd t\u1ef1&#8230;\u00a0<\/b><\/p>\n<p style=\"text-align: left;\"><b>&#8216;title&#8217; =&gt; &#8216;size:12&#8217;;\u00a0<\/b><\/p>\n<p style=\"text-align: left;\"><b>\/\/ X\u00e1c th\u1ef1c r\u1eb1ng m\u1ed9t s\u1ed1 nguy\u00ean \u0111\u01b0\u1ee3c cung c\u1ea5p b\u1eb1ng 10&#8230;\u00a0<\/b><\/p>\n<p style=\"text-align: left;\"><b>&#8216;seats&#8217; =&gt; &#8216;integer|size:10&#8217;;\u00a0<\/b><\/p>\n<p style=\"text-align: left;\"><b>\/\/ X\u00e1c th\u1ef1c r\u1eb1ng m\u1ed9t m\u1ea3ng c\u00f3 ch\u00ednh x\u00e1c 5 ph\u1ea7n t\u1eed&#8230;\u00a0<\/b><\/p>\n<p style=\"text-align: left;\"><b>&#8216;tags&#8217; =&gt; &#8216;array|size:5&#8217;;\u00a0<\/b><\/p>\n<p style=\"text-align: left;\"><b>\/\/ X\u00e1c th\u1ef1c r\u1eb1ng m\u1ed9t t\u1ec7p t\u1ea3i l\u00ean c\u00f3 ch\u00ednh x\u00e1c 512 kilobyte&#8230;\u00a0<\/b><\/p>\n<p style=\"text-align: left;\"><b>&#8216;image&#8217; =&gt; &#8216;file|size:512&#8217;;<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>starts_with:foo,bar,&#8230;<\/b><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i b\u1eaft \u0111\u1ea7u v\u1edbi m\u1ed9t trong c\u00e1c gi\u00e1 tr\u1ecb \u0111\u00e3 cho.<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>string<\/b><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t chu\u1ed7i. N\u1ebfu b\u1ea1n mu\u1ed1n cho ph\u00e9p tr\u01b0\u1eddng n\u00e0y c\u00f3 th\u1ec3 l\u00e0 null, b\u1ea1n n\u00ean g\u00e1n quy t\u1eafc nullable cho tr\u01b0\u1eddng n\u00e0y.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>timezone<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t m\u00e3 \u0111\u1ecbnh danh m\u00fai gi\u1edd h\u1ee3p l\u1ec7 theo ph\u01b0\u01a1ng th\u1ee9c DateTimeZone::listIdentifiers.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">B\u1ea1n c\u0169ng c\u00f3 th\u1ec3 cung c\u1ea5p c\u00e1c \u0111\u1ed1i s\u1ed1 \u0111\u01b0\u1ee3c ch\u1ea5p nh\u1eadn b\u1edfi ph\u01b0\u01a1ng th\u1ee9c DateTimeZone::listIdentifiers cho quy t\u1eafc ki\u1ec3m \u0111\u1ecbnh n\u00e0y:<\/span><\/p>\n<p><b>&#8216;timezone&#8217; =&gt; &#8216;required|timezone:all&#8217;;<\/b><\/p>\n<p><b>&#8216;timezone&#8217; =&gt; &#8216;required|timezone:Africa&#8217;;<\/b><\/p>\n<p><b>&#8216;timezone&#8217; =&gt; &#8216;required|timezone:per_country,US&#8217;;<\/b><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>unique:table,column<\/b><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c kh\u00f4ng \u0111\u01b0\u1ee3c t\u1ed3n t\u1ea1i trong b\u1ea3ng c\u01a1 s\u1edf d\u1eef li\u1ec7u \u0111\u00e3 cho.<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>uppercase<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 ch\u1eef hoa.<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\"><strong>url<\/strong>\u00a0<\/span><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t URL h\u1ee3p l\u1ec7.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">N\u1ebfu b\u1ea1n mu\u1ed1n ch\u1ec9 \u0111\u1ecbnh c\u00e1c giao th\u1ee9c URL n\u00e0o n\u00ean \u0111\u01b0\u1ee3c coi l\u00e0 h\u1ee3p l\u1ec7, b\u1ea1n c\u00f3 th\u1ec3 truy\u1ec1n c\u00e1c giao th\u1ee9c \u0111\u00f3 l\u00e0m tham s\u1ed1 cho quy t\u1eafc x\u00e1c th\u1ef1c:\u00a0<\/span><\/p>\n<p style=\"text-align: left;\"><b>&#8216;url&#8217; =&gt; &#8216;url:http,https&#8217;,<\/b><\/p>\n<p style=\"text-align: left;\"><b>&#8216;game&#8217; =&gt; &#8216;url:minecraft,steam&#8217;,<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: left;\"><b>ulid<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<\/td>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t m\u00e3 \u0111\u1ecbnh danh duy nh\u1ea5t to\u00e0n c\u1ea7u c\u00f3 th\u1ec3 s\u1eafp x\u1ebfp theo th\u1ee9 t\u1ef1 t\u1eeb \u0111i\u1ec3n (ULID) h\u1ee3p l\u1ec7.<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><b>uuid<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/td>\n<td>\n<p style=\"text-align: left;\"><span style=\"font-weight: 400;\">Tr\u01b0\u1eddng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c ph\u1ea3i l\u00e0 m\u1ed9t m\u00e3 \u0111\u1ecbnh danh duy nh\u1ea5t to\u00e0n c\u1ea7u (UUID) h\u1ee3p l\u1ec7 theo RFC 4122 (phi\u00ean b\u1ea3n 1, 3, 4 ho\u1eb7c 5).<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">C\u00e1c quy t\u1eafc x\u00e1c th\u1ef1c Laravel c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c b\u1ed5 sung, thay \u0111\u1ed5i ho\u1eb7c lo\u1ea1i b\u1ecf t\u00f9y theo phi\u00ean b\u1ea3n. B\u00ean c\u1ea1nh c\u00e1c quy t\u1eafc \u0111\u01b0\u1ee3c li\u1ec7t k\u00ea \u1edf tr\u00ean, c\u00f2n nhi\u1ec1u quy t\u1eafc kh\u00e1c m\u00e0 b\u1ea1n c\u00f3 th\u1ec3 \u1ee9ng d\u1ee5ng v\u00e0o qu\u00e1 tr\u00ecnh x\u00e1c th\u1ef1c d\u1eef li\u1ec7u c\u1ee7a m\u00ecnh.<\/span><\/p>\n<blockquote><p><span style=\"font-weight: 400;\">\u0110\u1ec3 c\u1eadp nh\u1eadt th\u00f4ng tin ch\u00ednh x\u00e1c v\u00e0 m\u1edbi nh\u1ea5t, b\u1ea1n c\u00f3 th\u1ec3 truy c\u1eadp t\u00e0i li\u1ec7u ch\u00ednh th\u1ee9c c\u1ee7a Laravel v\u1ec1<\/span> <a href=\"https:\/\/laravel.com\/docs\/11.x\/validation#available-validation-rules:~:text=is%20credit%20card.-,Available%20Validation%20Rules,-Below%20is%20a\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">C\u00e1c quy t\u1eafc x\u00e1c th\u1ef1c s\u1eb5n c\u00f3<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p><\/blockquote>\n<h2><span class=\"ez-toc-section\" id=\"Huong_dan_cach_tao_quy_tac_Laravel_validation\"><\/span><b>H\u01b0\u1edbng d\u1eabn c\u00e1ch t\u1ea1o quy t\u1eafc Laravel validation<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Khi n\u00f3i \u0111\u1ebfn x\u00e1c th\u1ef1c d\u1eef li\u1ec7u cho c\u00e1c website v\u00e0 \u1ee9ng d\u1ee5ng Laravel, ch\u00fang ta th\u01b0\u1eddng s\u1eed d\u1ee5ng hai c\u00e1ch ph\u01b0\u01a1ng ph\u00e1p kh\u00e1c nhau: S\u1eed d\u1ee5ng c\u00e1c quy t\u1eafc t\u00edch h\u1ee3p s\u1eb5n v\u00e0 t\u1ea1o c\u00e1c quy t\u1eafc t\u00f9y ch\u1ec9nh.\u00a0<\/span><\/p>\n<h3><b>S\u1eed d\u1ee5ng c\u00e1c quy t\u1eafc Validation t\u00edch h\u1ee3p s\u1eb5n<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Laravel cung c\u1ea5p m\u1ed9t t\u1eadp h\u1ee3p quy t\u1eafc x\u00e1c th\u1ef1c \u0111\u01b0\u1ee3c \u0111\u1ecbnh ngh\u0129a tr\u01b0\u1edbc \u0111\u1ec3 x\u1eed l\u00fd c\u00e1c t\u00ecnh hu\u1ed1ng ph\u1ed5 bi\u1ebfn. B\u1ea1n c\u00f3 th\u1ec3 t\u1eadn d\u1ee5ng c\u00e1c quy t\u1eafc n\u00e0y trong Controllers v\u00e0 Form Request Classes c\u1ee7a m\u00ecnh.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Controllers:<\/b><span style=\"font-weight: 400;\"> Trong controllers, b\u1ea1n c\u00f3 th\u1ec3 \u0111\u1ecbnh ngh\u0129a c\u00e1c quy t\u1eafc x\u00e1c th\u1ef1c tr\u1ef1c ti\u1ebfp trong ph\u01b0\u01a1ng th\u1ee9c nh\u01b0 store. Ph\u01b0\u01a1ng th\u1ee9c n\u00e0y tr\u1ea3 v\u1ec1 m\u1ed9t m\u1ea3ng k\u1ebft h\u1ee3p, trong \u0111\u00f3 key l\u00e0 t\u00ean tr\u01b0\u1eddng v\u00e0 value l\u00e0 c\u00e1c quy t\u1eafc x\u00e1c th\u1ef1c \u0111\u01b0\u1ee3c \u00e1p d\u1ee5ng cho tr\u01b0\u1eddng \u0111\u00f3.\u00a0<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">public function store(Request $request)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">{<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0$rules = [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'name' =&gt; 'required|string|max:255',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'email' =&gt; 'required|email|unique:users,email',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0];<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\/\/ ... ph\u1ea7n c\u00f2n l\u1ea1i c\u1ee7a logic controller<\/span>\r\n\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Form Request Classes:<\/b><span style=\"font-weight: 400;\"> T\u1ea1o m\u1ed9t l\u1edbp form request ri\u00eang bi\u1ec7t k\u1ebf th\u1eeba l\u1edbp Illuminate\\Foundation\\Http\\FormRequest. \u0110\u1ecbnh ngh\u0129a c\u00e1c quy t\u1eafc t\u01b0\u01a1ng t\u1ef1 nh\u01b0 controller v\u00e0 s\u1eed d\u1ee5ng ph\u01b0\u01a1ng th\u1ee9c authorize \u0111\u1ec3 th\u00eam logic \u1ee7y quy\u1ec1n.<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">class StoreUserRequest extends FormRequest<\/span>\r\n\r\n<span style=\"font-weight: 400;\">{<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0public function rules()<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0{<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'name' =&gt; 'required|string|max:255',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'email' =&gt; 'required|email|unique:users,email',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0];<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0public function authorize()<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0{<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><b>\u00a0<\/b><span style=\"font-weight: 400;\">\u00a0return true; \/\/ Thay th\u1ebf b\u1eb1ng logic \u1ee7y quy\u1ec1n c\u1ee7a b\u1ea1n<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<h3><b>T\u1ea1o c\u00e1c quy t\u1eafc Validation t\u00f9y ch\u1ec9nh<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3 s\u1eed t\u00ecnh hu\u1ed1ng c\u1ee7a b\u1ea1n v\u01b0\u1ee3t ra ngo\u00e0i ph\u1ea1m vi c\u1ee7a c\u00e1c quy t\u1eafc t\u00edch h\u1ee3p s\u1eb5n. Trong tr\u01b0\u1eddng h\u1ee3p \u0111\u00f3, b\u1ea1n c\u00f3 th\u1ec3 t\u1ea1o c\u00e1c quy t\u1eafc validation t\u00f9y ch\u1ec9nh. \u0110i\u1ec1u n\u00e0y bao g\u1ed3m:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>T\u1ea1o m\u1ed9t l\u1edbp quy t\u1eafc (rule class): <\/b><span style=\"font-weight: 400;\">M\u1edf r\u1ed9ng l\u1edbp Illuminate\\Contracts\\Validation\\Rule Illuminate\\Validation\\Rule v\u00e0 \u0111\u1ecbnh ngh\u0129a hai ph\u01b0\u01a1ng th\u1ee9c:<\/span>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">passes: Ph\u01b0\u01a1ng th\u1ee9c n\u00e0y nh\u1eadn gi\u00e1 tr\u1ecb c\u1ea7n x\u00e1c th\u1ef1c, t\u00ean thu\u1ed9c t\u00ednh v\u00e0 m\u1ed9t h\u00e0m callback (t\u00f9y ch\u1ecdn). N\u00f3 tr\u1ea3 v\u1ec1 true n\u1ebfu x\u00e1c th\u1ef1c th\u00e0nh c\u00f4ng, false n\u1ebfu th\u1ea5t b\u1ea1i.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">message: Ph\u01b0\u01a1ng th\u1ee9c n\u00e0y tr\u1ea3 v\u1ec1 th\u00f4ng b\u00e1o l\u1ed7i n\u1ebfu x\u00e1c th\u1ef1c th\u1ea5t b\u1ea1i.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">use Illuminate\\Contracts\\Validation\\Rule;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">class IsUpperCaseRule extends Rule<\/span>\r\n\r\n<span style=\"font-weight: 400;\">{<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0public function passes($attribute, $value)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0{<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return mb_strtoupper($value) === $value;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0public function message()<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0{<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return 'The :attribute field must be in uppercase.';<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng quy t\u1eafc t\u00f9y ch\u1ec9nh: Sau khi t\u1ea1o, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng quy t\u1eafc t\u00f9y ch\u1ec9nh c\u1ee7a m\u00ecnh nh\u01b0 b\u1ea5t k\u1ef3 quy t\u1eafc t\u00edch h\u1ee3p s\u1eb5n n\u00e0o kh\u00e1c trong ph\u01b0\u01a1ng th\u1ee9c rules:<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">$rules = [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0'title' =&gt; 'required|string|max:255',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0'content' =&gt; 'required|string',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0'custom_field' =&gt; [new IsUpperCaseRule],<\/span>\r\n\r\n<span style=\"font-weight: 400;\">];<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Ho\u1eb7c trong Form Request Class:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">public function rules()<\/span>\r\n\r\n<span style=\"font-weight: 400;\">{<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0return [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'title' =&gt; 'required|string|max:255',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'content' =&gt; 'required|string',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'custom_field' =&gt; [new IsUpperCaseRule],<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0];<\/span>\r\n\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><b>L\u01b0u \u00fd:<\/b><span style=\"font-weight: 400;\"> H\u00e3y ch\u1eafc ch\u1eafn r\u1eb1ng b\u1ea1n thay th\u1ebf c\u00e1c placeholder &#8220;name&#8221; v\u00e0 &#8220;email&#8221; b\u1eb1ng t\u00ean tr\u01b0\u1eddng th\u1ef1c t\u1ebf c\u1ee7a b\u1ea1n, c\u0169ng nh\u01b0 \u0111i\u1ec1u ch\u1ec9nh c\u00e1c quy t\u1eafc v\u00e0 th\u00f4ng b\u00e1o d\u1ef1a tr\u00ean y\u00eau c\u1ea7u c\u1ee7a b\u1ea1n.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cach_ap_dung_cac_quy_tac_Laravel_Validation\"><\/span><b>C\u00e1ch \u00e1p d\u1ee5ng c\u00e1c quy t\u1eafc Laravel Validation<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">\u0110\u1ec3 \u00e1p d\u1ee5ng c\u00e1c quy t\u1eafc x\u00e1c th\u1ef1c trong c\u00e1c trang web ho\u1eb7c \u1ee9ng d\u1ee5ng Laravel, b\u1ea1n c\u1ea7n t\u00edch h\u1ee3p ch\u00fang v\u00e0o quy tr\u00ecnh ho\u1ea1t \u0111\u1ed9ng c\u1ee7a \u1ee9ng d\u1ee5ng. C\u00f3 hai ph\u01b0\u01a1ng ph\u00e1p \u0111\u1ec3 th\u1ef1c hi\u1ec7n \u0111i\u1ec1u n\u00e0y:<\/span><\/p>\n<h3><b>S\u1eed d\u1ee5ng x\u00e1c th\u1ef1c v\u1edbi Requests<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Ph\u01b0\u01a1ng ph\u00e1p n\u00e0y \u00e1p d\u1ee5ng c\u00e1c quy t\u1eafc x\u00e1c th\u1ef1c trong Laravel s\u1eed d\u1ee5ng ph\u01b0\u01a1ng th\u1ee9c validate \u0111\u01b0\u1ee3c cung c\u1ea5p b\u1edfi \u0111\u1ed1i t\u01b0\u1ee3ng Illuminate\\Http\\Request:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">public function store(Request $request)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">{<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0$rules = [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'name' =&gt; 'required|string|max:255',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'email' =&gt; 'required|email|unique:users,email',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0];<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0$request-&gt;validate($rules);<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\/\/ ... ph\u1ea7n c\u00f2n l\u1ea1i c\u1ee7a logic controller, n\u01a1i d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c \u0111\u1ea3m b\u1ea3o h\u1ee3p l\u1ec7<\/span>\r\n\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong ph\u01b0\u01a1ng ph\u00e1p n\u00e0y, ph\u01b0\u01a1ng th\u1ee9c validate nh\u1eadn c\u00e1c quy t\u1eafc x\u00e1c th\u1ef1c l\u00e0m tham s\u1ed1. N\u00f3 th\u1ef1c hi\u1ec7n x\u00e1c th\u1ef1c \u0111\u1ed1i v\u1edbi d\u1eef li\u1ec7u request. N\u00f3 c\u0169ng th\u1ec3 hi\u1ec7n m\u1ed9t ngo\u1ea1i l\u1ec7 (ValidationException) n\u1ebfu x\u00e1c th\u1ef1c th\u1ea5t b\u1ea1i, v\u00e0 t\u1ef1 \u0111\u1ed9ng chuy\u1ec3n h\u01b0\u1edbng ng\u01b0\u1eddi d\u00f9ng quay l\u1ea1i URL tr\u01b0\u1edbc \u0111\u00f3.<\/span><\/p>\n<h3><b>S\u1eed d\u1ee5ng Form Request Classes<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Ph\u01b0\u01a1ng ph\u00e1p n\u00e0y li\u00ean quan \u0111\u1ebfn vi\u1ec7c t\u1ea1o m\u1ed9t l\u1edbp Form Request ri\u00eang bi\u1ec7t:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>T\u1ea1o m\u1ed9t l\u1edbp Form Request: <\/b><span style=\"font-weight: 400;\">K\u1ebf th\u1eeba l\u1edbp Illuminate\\Foundation\\Http\\FormRequest v\u00e0 \u0111\u1ecbnh ngh\u0129a c\u00e1c ph\u01b0\u01a1ng th\u1ee9c sau:<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">rules: \u0110\u1ecbnh ngh\u0129a c\u00e1c quy t\u1eafc x\u00e1c th\u1ef1c trong ph\u01b0\u01a1ng th\u1ee9c n\u00e0y, t\u01b0\u01a1ng t\u1ef1 nh\u01b0 c\u00e1ch ti\u1ebfp c\u1eadn trong controller.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">authorize (t\u00f9y ch\u1ecdn): Th\u1ef1c hi\u1ec7n b\u1ea5t k\u1ef3 logic \u1ee7y quy\u1ec1n n\u00e0o c\u1ee5 th\u1ec3 cho request.<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">class StoreUserRequest extends FormRequest<\/span>\r\n\r\n<span style=\"font-weight: 400;\">{<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0public function rules()<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0{<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'name' =&gt; 'required|string|max:255',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'email' =&gt; 'required|email|unique:users,email',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0];<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0public function authorize()<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0{<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return true; \/\/ Thay th\u1ebf b\u1eb1ng logic \u1ee7y quy\u1ec1n c\u1ee7a b\u1ea1n<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">}<\/span><b><\/b><\/pre>\n<h3><b>S\u1eed d\u1ee5ng l\u1edbp Form Request trong Controller<\/b><\/h3>\n<pre><span style=\"font-weight: 400;\">public function store(StoreUserRequest $request)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">{<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\/\/ Truy c\u1eadp d\u1eef li\u1ec7u \u0111\u00e3 \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c tr\u1ef1c ti\u1ebfp t\u1eeb \u0111\u1ed1i t\u01b0\u1ee3ng request<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0$name = $request-&gt;name;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0$email = $request-&gt;email;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\/\/ ... ph\u1ea7n c\u00f2n l\u1ea1i c\u1ee7a logic controller, n\u01a1i d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c \u0111\u1ea3m b\u1ea3o h\u1ee3p l\u1ec7<\/span>\r\n\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">\u1ede \u0111\u00e2y, l\u1edbp StoreUserRequest x\u1eed l\u00fd x\u00e1c th\u1ef1c v\u00e0 controller nh\u1eadn d\u1eef li\u1ec7u \u0111\u00e3 \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c tr\u1ef1c ti\u1ebfp th\u00f4ng qua \u0111\u1ed1i t\u01b0\u1ee3ng request. C\u00e1ch ti\u1ebfp c\u1eadn n\u00e0y t\u00e1ch bi\u1ec7t logic x\u00e1c th\u1ef1c ra kh\u1ecfi controller \u0111\u1ec3 c\u00f3 t\u1ed5 ch\u1ee9c code s\u1ea1ch h\u01a1n.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">M\u1eb7c d\u00f9 c\u1ea3 hai ph\u01b0\u01a1ng ph\u00e1p \u0111\u1ec1u hi\u1ec7u qu\u1ea3, b\u1ea1n c\u1ea7n ch\u1ecdn ph\u01b0\u01a1ng ph\u00e1p ph\u00f9 h\u1ee3p nh\u1ea5t v\u1edbi c\u1ea5u tr\u00fac trang web ho\u1eb7c \u1ee9ng d\u1ee5ng c\u1ee7a m\u00ecnh.\u00a0<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cach_ap_dung_Laravel_Validation_de_xac_thuc_mang_Array\"><\/span><b>C\u00e1ch \u00e1p d\u1ee5ng Laravel Validation \u0111\u1ec3 x\u00e1c th\u1ef1c m\u1ea3ng (Array)<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Quy t\u1eafc array ch\u1ea5p nh\u1eadn m\u1ed9t danh s\u00e1ch c\u00e1c kh\u00f3a m\u1ea3ng \u0111\u01b0\u1ee3c cho ph\u00e9p. N\u1ebfu b\u1ea5t k\u1ef3 kh\u00f3a b\u1ed5 sung n\u00e0o xu\u1ea5t hi\u1ec7n trong m\u1ea3ng, vi\u1ec7c x\u00e1c th\u1ef1c s\u1ebd th\u1ea5t b\u1ea1i:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">use Illuminate\\Support\\Facades\\Validator;<\/span>\r\n\r\n\r\n<span style=\"font-weight: 400;\">$input = [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0'user' =&gt; [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'name' =&gt; 'Taylor Otwell',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'username' =&gt; 'taylorotwell',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'admin' =&gt; true,<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0],<\/span>\r\n\r\n<span style=\"font-weight: 400;\">];<\/span>\r\n\r\n\r\n<span style=\"font-weight: 400;\">Validator::make($input, [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0'user' =&gt; 'array:name,username',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">]);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">L\u01b0u \u00fd: Th\u00f4ng th\u01b0\u1eddng, b\u1ea1n n\u00ean ch\u1ec9 \u0111\u1ecbnh c\u00e1c kh\u00f3a m\u1ea3ng \u0111\u01b0\u1ee3c ph\u00e9p c\u00f3 m\u1eb7t trong m\u1ea3ng c\u1ee7a m\u00ecnh. N\u1ebfu kh\u00f4ng, c\u00e1c ph\u01b0\u01a1ng th\u1ee9c validate v\u00e0 validated c\u1ee7a tr\u00ecnh ki\u1ec3m duy\u1ec7t s\u1ebd tr\u1ea3 v\u1ec1 t\u1ea5t c\u1ea3 d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c, bao g\u1ed3m c\u1ea3 m\u1ea3ng v\u00e0 t\u1ea5t c\u1ea3 c\u00e1c kh\u00f3a c\u1ee7a n\u00f3, ngay c\u1ea3 khi c\u00e1c kh\u00f3a \u0111\u00f3 kh\u00f4ng \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c b\u1edfi c\u00e1c quy t\u1eafc x\u00e1c th\u1ef1c m\u1ea3ng l\u1ed3ng nhau kh\u00e1c.<\/span><b><\/b><\/p>\n<h3><b>X\u00e1c th\u1ef1c m\u1ea3ng l\u1ed3ng nhau<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Vi\u1ec7c x\u00e1c th\u1ef1c d\u1eef li\u1ec7u t\u1eeb c\u00e1c tr\u01b0\u1eddng nh\u1eadp li\u1ec7u d\u1ea1ng m\u1ea3ng l\u1ed3ng nhau trong Laravel kh\u00f4ng h\u1ec1 kh\u00f3 kh\u0103n nh\u01b0 b\u1ea1n ngh\u0129. Nh\u1edd &#8220;k\u00fd hi\u1ec7u ch\u1ea5m&#8221;, b\u1ea1n c\u00f3 th\u1ec3 d\u1ec5 d\u00e0ng ki\u1ec3m tra c\u00e1c thu\u1ed9c t\u00ednh b\u00ean trong m\u1ed9t m\u1ea3ng.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3 s\u1eed b\u1ea1n c\u00f3 tr\u01b0\u1eddng photos[profile] trong y\u00eau c\u1ea7u HTTP. \u0110\u1ec3 ki\u1ec3m tra tr\u01b0\u1eddng n\u00e0y, b\u1ea1n ch\u1ec9 c\u1ea7n vi\u1ebft \u0111\u01a1n gi\u1ea3n nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">use Illuminate\\Support\\Facades\\Validator;<\/span>\r\n\r\n\r\n<span style=\"font-weight: 400;\">$validator = Validator::make($request-&gt;all(), [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0'photos.profile' =&gt; 'required|image',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">]);<\/span><b><\/b><\/pre>\n<h3><b>X\u00e1c th\u1ef1c t\u1eebng ph\u1ea7n t\u1eed c\u1ee7a m\u1ea3ng<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3 s\u1eed b\u1ea1n c\u00f3 m\u1ed9t m\u1ea3ng person ch\u1ee9a nhi\u1ec1u ng\u01b0\u1eddi d\u00f9ng, m\u1ed7i ng\u01b0\u1eddi c\u00f3 email v\u00e0 t\u00ean. B\u1ea1n mu\u1ed1n \u0111\u1ea3m b\u1ea3o r\u1eb1ng m\u1ed7i email l\u00e0 duy nh\u1ea5t v\u00e0 t\u00ean v\u00e0 h\u1ecd \u0111i k\u00e8m v\u1edbi nhau.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u1edbi Laravel, b\u1ea1n c\u00f3 th\u1ec3 d\u1ec5 d\u00e0ng th\u1ef1c hi\u1ec7n \u0111i\u1ec1u n\u00e0y b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng quy t\u1eafc validation sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">$validator = Validator::make($request-&gt;all(), [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0'person.*.email' =&gt; 'email|unique:users',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0'person.*.first_name' =&gt; 'required_with:person.*.last_name',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">]);<\/span><b><\/b><\/pre>\n<h3><b>Th\u00f4ng b\u00e1o l\u1ed7i t\u00f9y ch\u1ec9nh cho m\u1ea3ng<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">T\u01b0\u01a1ng t\u1ef1, Laravel s\u1ebd t\u1ea1o ra c\u00e1c th\u00f4ng b\u00e1o l\u1ed7i m\u1eb7c \u0111\u1ecbnh. Tuy nhi\u00ean, b\u1ea1n c\u00f3 th\u1ec3 t\u00f9y ch\u1ec9nh th\u00f4ng b\u00e1o l\u1ed7i cho ph\u00f9 h\u1ee3p v\u1edbi ng\u1eef c\u1ea3nh c\u1ee7a m\u00ecnh. V\u00ed d\u1ee5:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">'custom' =&gt; [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0'person.*.email' =&gt; [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'unique' =&gt; 'M\u1ed7i ng\u01b0\u1eddi d\u00f9ng ph\u1ea3i c\u00f3 m\u1ed9t \u0111\u1ecba ch\u1ec9 email duy nh\u1ea5t',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0]<\/span>\r\n\r\n<span style=\"font-weight: 400;\">],<\/span><b><\/b><\/pre>\n<h3><b>Truy xu\u1ea5t d\u1eef li\u1ec7u m\u1ea3ng l\u1ed3ng nhau<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Trong m\u1ed9t s\u1ed1 tr\u01b0\u1eddng h\u1ee3p, b\u1ea1n c\u1ea7n truy c\u1eadp gi\u00e1 tr\u1ecb c\u1ee7a m\u1ed9t ph\u1ea7n t\u1eed c\u1ee5 th\u1ec3 trong m\u1ea3ng l\u1ed3ng nhau khi thi\u1ebft l\u1eadp c\u00e1c quy t\u1eafc validation cho thu\u1ed9c t\u00ednh. Laravel cung c\u1ea5p ph\u01b0\u01a1ng th\u1ee9c Rule::forEach \u0111\u1ec3 h\u1ed7 tr\u1ee3 b\u1ea1n th\u1ef1c hi\u1ec7n \u0111i\u1ec1u n\u00e0y.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ph\u01b0\u01a1ng th\u1ee9c forEach nh\u1eadn m\u1ed9t closure (h\u00e0m \u1ea9n danh) s\u1ebd \u0111\u01b0\u1ee3c g\u1ecdi cho m\u1ed7i l\u1ea7n l\u1eb7p c\u1ee7a thu\u1ed9c t\u00ednh m\u1ea3ng \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c, closure n\u00e0y s\u1ebd nh\u1eadn hai tham s\u1ed1:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">$value: Gi\u00e1 tr\u1ecb c\u1ee7a ph\u1ea7n t\u1eed m\u1ea3ng hi\u1ec7n t\u1ea1i.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">$attribute: T\u00ean \u0111\u1ea7y \u0111\u1ee7 c\u1ee7a thu\u1ed9c t\u00ednh m\u1ea3ng, bao g\u1ed3m c\u1ea3 t\u00ean m\u1ea3ng cha.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Closure n\u00ean tr\u1ea3 v\u1ec1 m\u1ed9t m\u1ea3ng c\u00e1c quy t\u1eafc validation s\u1ebd \u0111\u01b0\u1ee3c \u00e1p d\u1ee5ng cho ph\u1ea7n t\u1eed m\u1ea3ng hi\u1ec7n t\u1ea1i:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">use App\\Rules\\HasPermission;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">use Illuminate\\Support\\Facades\\Validator;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">use Illuminate\\Validation\\Rule;<\/span>\r\n\r\n\r\n<span style=\"font-weight: 400;\">$validator = Validator::make($request-&gt;all(), [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0'companies.*.id' =&gt; Rule::forEach(function (string|null $value, string $attribute) {<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Rule::exists(Company::class, 'id'),<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0new HasPermission('manage-company', $value),<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0];<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}),<\/span>\r\n\r\n<span style=\"font-weight: 400;\">]);<\/span><b><\/b><\/pre>\n<h3><b>Ch\u1ec9 m\u1ee5c v\u00e0 v\u1ecb tr\u00ed trong th\u00f4ng b\u00e1o l\u1ed7i<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Khi x\u00e1c th\u1ef1c c\u00e1c m\u1ea3ng, b\u1ea1n c\u00f3 th\u1ec3 mu\u1ed1n tham chi\u1ebfu ch\u1ec9 m\u1ee5c ho\u1eb7c v\u1ecb tr\u00ed c\u1ee7a m\u1ed9t m\u1ee5c c\u1ee5 th\u1ec3 kh\u00f4ng v\u01b0\u1ee3t qua ki\u1ec3m duy\u1ec7t trong th\u00f4ng b\u00e1o l\u1ed7i m\u00e0 \u1ee9ng d\u1ee5ng c\u1ee7a b\u1ea1n hi\u1ec3n th\u1ecb. \u0110\u1ec3 th\u1ef1c hi\u1ec7n \u0111i\u1ec1u n\u00e0y, b\u1ea1n c\u00f3 th\u1ec3 bao g\u1ed3m c\u00e1c placeholder :index (b\u1eaft \u0111\u1ea7u t\u1eeb 0) v\u00e0 :position (b\u1eaft \u0111\u1ea7u t\u1eeb 1) trong th\u00f4ng b\u00e1o ki\u1ec3m duy\u1ec7t t\u00f9y ch\u1ec9nh c\u1ee7a m\u00ecnh:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">use Illuminate\\Support\\Facades\\Validator;<\/span>\r\n\r\n\r\n<span style=\"font-weight: 400;\">$input = [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0'photos' =&gt; [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'name' =&gt; 'BeachVacation.jpg<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0]<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0]<\/span>\r\n\r\n<span style=\"font-weight: 400;\">]<\/span><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Cach_ap_dung_Laravel_Validation_de_kiem_duyet_file\"><\/span><b>C\u00e1ch \u00e1p d\u1ee5ng Laravel Validation \u0111\u1ec3 ki\u1ec3m duy\u1ec7t file<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Laravel cung c\u1ea5p nhi\u1ec1u quy t\u1eafc kh\u00e1c nhau \u0111\u1ec3 ki\u1ec3m tra c\u00e1c file \u0111\u01b0\u1ee3c t\u1ea3i l\u00ean, ch\u1eb3ng h\u1ea1n nh\u01b0 mimes (ki\u1ec3u MIME), image (\u1ea3nh), min (dung l\u01b0\u1ee3ng t\u1ed1i thi\u1ec3u) v\u00e0 max (dung l\u01b0\u1ee3ng t\u1ed1i \u0111a).\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">M\u1eb7c d\u00f9 b\u1ea1n c\u00f3 th\u1ec3 thi\u1ebft l\u1eadp c\u00e1c quy t\u1eafc n\u00e0y ri\u00eang l\u1ebb, Laravel c\u0169ng cung c\u1ea5p m\u1ed9t tr\u00ecnh x\u00e2y d\u1ef1ng quy t\u1eafc theo chu\u1ed7i (fluent) \u0111\u1ec3 vi\u1ec7c ki\u1ec3m duy\u1ec7t thu\u1eadn ti\u1ec7n h\u01a1n:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">use Illuminate\\Support\\Facades\\Validator;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">use Illuminate\\Validation\\Rules\\File;<\/span>\r\n\r\n\r\n<span style=\"font-weight: 400;\">Validator::validate($input, [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0'attachment' =&gt; [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'required',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0File::types(['mp3', 'wav'])<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-&gt;min(1024) \/\/ Ki\u1ec3u byte<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-&gt;max(12 * 1024), \/\/ Ki\u1ec3u byte<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0],<\/span>\r\n\r\n<span style=\"font-weight: 400;\">]);<\/span>\r\n<b><\/b><\/pre>\n<h3><b>Ki\u1ec3m duy\u1ec7t file \u1ea3nh<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">N\u1ebfu \u1ee9ng d\u1ee5ng c\u1ee7a b\u1ea1n ch\u1ea5p nh\u1eadn \u1ea3nh do ng\u01b0\u1eddi d\u00f9ng t\u1ea3i l\u00ean, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng ph\u01b0\u01a1ng th\u1ee9c kh\u1edfi t\u1ea1o image c\u1ee7a quy t\u1eafc file \u0111\u1ec3 y\u00eau c\u1ea7u file \u0111\u01b0\u1ee3c t\u1ea3i l\u00ean ph\u1ea3i l\u00e0 m\u1ed9t \u1ea3nh. Ngo\u00e0i ra, quy t\u1eafc dimensions c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 gi\u1edbi h\u1ea1n k\u00edch th\u01b0\u1edbc c\u1ee7a \u1ea3nh:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">use Illuminate\\Support\\Facades\\Validator;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">use Illuminate\\Validation\\Rule;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">use Illuminate\\Validation\\Rules\\File;<\/span>\r\n\r\n\r\n<span style=\"font-weight: 400;\">Validator::validate($input, [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0'photo' =&gt; [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'required',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0File::image()<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-&gt;min(1024)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-&gt;max(12 * 1024)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-&gt;dimensions(Rule::dimensions()-&gt;maxWidth(1000)-&gt;maxHeight(500)),<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0],<\/span>\r\n\r\n<span style=\"font-weight: 400;\">]);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">B\u1ea1n c\u00f3 th\u1ec3 t\u00ecm th\u00eam th\u00f4ng tin v\u1ec1 vi\u1ec7c ki\u1ec3m tra k\u00edch th\u01b0\u1edbc \u1ea3nh trong<\/span> <a href=\"https:\/\/laravel.com\/docs\/11.x\/validation#rule-dimensions\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">t\u00e0i li\u1ec7u v\u1ec1 quy t\u1eafc dimensions<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><b><\/b><\/p>\n<h3><b>Ki\u1ec3m duy\u1ec7t dung l\u01b0\u1ee3ng file<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">M\u1ed9t c\u00e1ch \u0111\u01a1n gi\u1ea3n, b\u1ea1n c\u00f3 th\u1ec3 thi\u1ebft l\u1eadp dung l\u01b0\u1ee3ng file t\u1ed1i thi\u1ec3u v\u00e0 t\u1ed1i \u0111a d\u01b0\u1edbi d\u1ea1ng chu\u1ed7i, k\u00e8m theo h\u1eadu t\u1ed1 cho bi\u1ebft \u0111\u01a1n v\u1ecb dung l\u01b0\u1ee3ng. Laravel h\u1ed7 tr\u1ee3 c\u00e1c \u0111\u01a1n v\u1ecb kb (kilobyte), mb (megabyte), gb (gigabyte) v\u00e0 tb (terabyte):<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">File::image()<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0-&gt;min('1kb')<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0-&gt;max('10mb')<\/span><b><\/b><\/pre>\n<h3><b>Ki\u1ec3m duy\u1ec7t ki\u1ec3u file<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">M\u1eb7c d\u00f9 ph\u01b0\u01a1ng th\u1ee9c types ch\u1ec9 y\u00eau c\u1ea7u b\u1ea1n cung c\u1ea5p ph\u1ea7n m\u1edf r\u1ed9ng (nh\u01b0 .jpg, .png), nh\u01b0ng th\u1ef1c t\u1ebf n\u00f3 ki\u1ec3m tra chi ti\u1ebft h\u01a1n, v\u00ed d\u1ee5 nh\u01b0 ki\u1ec3m tra lo\u1ea1i MIME c\u1ee7a file b\u1eb1ng c\u00e1ch \u0111\u1ecdc n\u1ed9i dung file v\u00e0 \u0111o\u00e1n lo\u1ea1i MIME c\u1ee7a n\u00f3.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">File::types(['jpg', 'png'])<\/span><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Cach_ap_dung_Laravel_Validation_de_xac_thuc_mat_khau\"><\/span><b>C\u00e1ch \u00e1p d\u1ee5ng Laravel Validation \u0111\u1ec3 x\u00e1c th\u1ef1c m\u1eadt kh\u1ea9u<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">\u0110\u1ec3 \u0111\u1ea3m b\u1ea3o m\u1eadt kh\u1ea9u \u0111\u1ee7 \u0111\u1ed9 ph\u1ee9c t\u1ea1p, Laravel cung c\u1ea5p \u0111\u1ed1i t\u01b0\u1ee3ng Password:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">use Illuminate\\Support\\Facades\\Validator;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">use Illuminate\\Validation\\Rules\\Password;<\/span>\r\n\r\n\r\n<span style=\"font-weight: 400;\">$validator = Validator::make($request-&gt;all(), [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0'password' =&gt; ['required', 'confirmed', Password::min(8)],<\/span>\r\n\r\n<span style=\"font-weight: 400;\">]);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">\u0110\u1ed1i t\u01b0\u1ee3ng Password cho ph\u00e9p b\u1ea1n d\u1ec5 d\u00e0ng t\u00f9y ch\u1ec9nh c\u00e1c y\u00eau c\u1ea7u v\u1ec1 \u0111\u1ed9 ph\u1ee9c t\u1ea1p c\u1ee7a m\u1eadt kh\u1ea9u cho \u1ee9ng d\u1ee5ng c\u1ee7a m\u00ecnh, ch\u1eb3ng h\u1ea1n nh\u01b0 ch\u1ec9 \u0111\u1ecbnh r\u1eb1ng m\u1eadt kh\u1ea9u y\u00eau c\u1ea7u \u00edt nh\u1ea5t m\u1ed9t ch\u1eef c\u00e1i, s\u1ed1, k\u00fd hi\u1ec7u ho\u1eb7c k\u00fd t\u1ef1 c\u00f3 ki\u1ec3u vi\u1ebft hoa h\u1ed7n h\u1ee3p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">\/\/ Y\u00eau c\u1ea7u \u00edt nh\u1ea5t 8 k\u00fd t\u1ef1...<\/span>\r\n\r\n<span style=\"font-weight: 400;\">Password::min(8)\r\n<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\/\/ Y\u00eau c\u1ea7u \u00edt nh\u1ea5t 8 ch\u1eef c\u00e1i...<\/span>\r\n\r\n<span style=\"font-weight: 400;\">Password::min(8)-&gt;letters()\r\n<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\/\/ Y\u00eau c\u1ea7u \u00edt nh\u1ea5t m\u1ed9t ch\u1eef hoa v\u00e0 m\u1ed9t ch\u1eef th\u01b0\u1eddng...<\/span>\r\n\r\n<span style=\"font-weight: 400;\">Password::min(8)-&gt;mixedCase()<\/span>\r\n\r\n\r\n<span style=\"font-weight: 400;\">\/\/ Y\u00eau c\u1ea7u \u00edt nh\u1ea5t m\u1ed9t s\u1ed1\u2026<\/span>\r\n\r\n<span style=\"font-weight: 400;\">Password::min(8)-&gt;numbers()<\/span>\r\n\r\n\r\n<span style=\"font-weight: 400;\">\/\/ Y\u00eau c\u1ea7u \u00edt nh\u1ea5t m\u1ed9t bi\u1ec3u t\u01b0\u1ee3ng\u2026<\/span>\r\n\r\n<span style=\"font-weight: 400;\">Password::min(8)-&gt;symbols()<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Ngo\u00e0i ra, b\u1ea1n c\u00f3 th\u1ec3 \u0111\u1ea3m b\u1ea3o r\u1eb1ng m\u1eadt kh\u1ea9u kh\u00f4ng b\u1ecb l\u1ed9 trong c\u00e1c v\u1ee5 r\u00f2 r\u1ec9 d\u1eef li\u1ec7u m\u1eadt kh\u1ea9u c\u00f4ng khai b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng ph\u01b0\u01a1ng th\u1ee9c uncompromised:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">Password::min(8)-&gt;uncompromised()<\/span><\/pre>\n<h3><b>L\u01b0u \u00fd v\u1ec1 Quy\u1ec1n Ri\u00eang T\u01b0<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">\u0110\u1ed1i t\u01b0\u1ee3ng quy t\u1eafc Password s\u1eed d\u1ee5ng m\u00f4 h\u00ecnh k-Anonymity \u0111\u1ec3 x\u00e1c \u0111\u1ecbnh xem m\u1eadt kh\u1ea9u c\u00f3 b\u1ecb r\u00f2 r\u1ec9 qua d\u1ecbch v\u1ee5 haveibeenpwned.com m\u00e0 kh\u00f4ng x\u00e2m ph\u1ea1m quy\u1ec1n ri\u00eang t\u01b0 ho\u1eb7c b\u1ea3o m\u1eadt c\u1ee7a ng\u01b0\u1eddi d\u00f9ng.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">haveibeenpwned.com l\u00e0 m\u1ed9t d\u1ecbch v\u1ee5 mi\u1ec5n ph\u00ed cung c\u1ea5p c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u1ec1 c\u00e1c m\u1eadt kh\u1ea9u b\u1ecb r\u00f2 r\u1ec9. Theo m\u1eb7c \u0111\u1ecbnh, m\u1eadt kh\u1ea9u xu\u1ea5t hi\u1ec7n \u00edt nh\u1ea5t m\u1ed9t l\u1ea7n trong danh s\u00e1ch r\u00f2 r\u1ec9 s\u1ebd b\u1ecb \u0111\u00e1nh gi\u00e1 l\u00e0 r\u1ee7i ro.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">B\u1ea1n c\u00f3 th\u1ec3 t\u00f9y ch\u1ec9nh ng\u01b0\u1ee1ng n\u00e0y b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng \u0111\u1ed1i s\u1ed1 \u0111\u1ea7u ti\u00ean c\u1ee7a uncompromised:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">\/\/ Cho ph\u00e9p m\u1eadt kh\u1ea9u xu\u1ea5t hi\u1ec7n t\u1ed1i \u0111a 2 l\u1ea7n<\/span>\r\n\r\n<span style=\"font-weight: 400;\">Password::min(8)-&gt;uncompromised(3);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">B\u1ea1n c\u00f3 th\u1ec3 k\u1ebft h\u1ee3p c\u00e1c t\u00f9y ch\u1ecdn ki\u1ec3m tra trong v\u00ed d\u1ee5 tr\u00ean:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">Password::min(8)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0-&gt;letters()<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0-&gt;mixedCase()<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0-&gt;numbers()<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0-&gt;symbols()<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0-&gt;uncompromised();<\/span><b><\/b><\/pre>\n<h3><b>Thi\u1ebft l\u1eadp c\u00e1c quy t\u1eafc ki\u1ec3m tra m\u1eadt kh\u1ea9u m\u1eb7c \u0111\u1ecbnh<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Thi\u1ebft l\u1eadp c\u00e1c quy t\u1eafc ki\u1ec3m tra m\u1eadt kh\u1ea9u m\u1eb7c \u0111\u1ecbnh cho to\u00e0n b\u1ed9 \u1ee9ng d\u1ee5ng \u1edf m\u1ed9t v\u1ecb tr\u00ed thu\u1eadn ti\u1ec7n c\u00f3 th\u1ec3 gi\u00fap b\u1ea1n ti\u1ebft ki\u1ec7m th\u1eddi gian v\u00e0 c\u00f4ng s\u1ee9c. Laravel cung c\u1ea5p ph\u01b0\u01a1ng th\u1ee9c Password::defaults() \u0111\u1ec3 th\u1ef1c hi\u1ec7n \u0111i\u1ec1u n\u00e0y. Ph\u01b0\u01a1ng th\u1ee9c n\u00e0y ch\u1ea5p nh\u1eadn m\u1ed9t closure (h\u00e0m \u1ea9n danh) tr\u1ea3 v\u1ec1 c\u1ea5u h\u00ecnh m\u1eb7c \u0111\u1ecbnh c\u1ee7a quy t\u1eafc Password.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Th\u00f4ng th\u01b0\u1eddng, b\u1ea1n n\u00ean \u0111\u1eb7t closure n\u00e0y trong ph\u01b0\u01a1ng th\u1ee9c kh\u1edfi \u0111\u1ed9ng (boot) c\u1ee7a m\u1ed9t trong c\u00e1c nh\u00e0 cung c\u1ea5p d\u1ecbch v\u1ee5 cho \u1ee9ng d\u1ee5ng c\u1ee7a b\u1ea1n:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">use Illuminate\\Validation\\Rules\\Password;<\/span>\u00a0 \u00a0\u00a0<span style=\"font-weight: 400;\">\/**<\/span>\r\n\r\n<span style=\"font-weight: 400;\">* Bootstrap any application services.<\/span>\r\n\r\n<span style=\"font-weight: 400;\">*\/<\/span>\r\n\r\n<span style=\"font-weight: 400;\">public function boot(): void<\/span>\r\n\r\n<span style=\"font-weight: 400;\">{<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0Password::defaults(function () {<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$rule = Password::min(8);<\/span>\r\n\r\n \r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return $this-&gt;app-&gt;isProduction()<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0? $rule-&gt;mixedCase()-&gt;uncompromised()<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0: $rule;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0});<\/span>\r\n\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Sau \u0111\u00f3, khi b\u1ea1n mu\u1ed1n \u00e1p d\u1ee5ng c\u00e1c quy t\u1eafc m\u1eb7c \u0111\u1ecbnh cho m\u1ed9t m\u1eadt kh\u1ea9u c\u1ee5 th\u1ec3 \u0111ang \u0111\u01b0\u1ee3c x\u00e1c th\u1ef1c, b\u1ea1n c\u00f3 th\u1ec3 g\u1ecdi ph\u01b0\u01a1ng th\u1ee9c defaults m\u00e0 kh\u00f4ng c\u1ea7n cung c\u1ea5p \u0111\u1ed1i s\u1ed1:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">'password' =&gt; ['required', Password::defaults()],<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong tr\u01b0\u1eddng h\u1ee3p b\u1ea1n mu\u1ed1n \u0111\u00ednh k\u00e8m c\u00e1c quy t\u1eafc x\u00e1c th\u1ef1c b\u1ed5 sung v\u00e0o c\u00e1c quy t\u1eafc x\u00e1c th\u1ef1c m\u1eadt kh\u1ea9u m\u1eb7c \u0111\u1ecbnh c\u1ee7a m\u00ecnh, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng ph\u01b0\u01a1ng th\u1ee9c rules \u0111\u1ec3 th\u1ef1c hi\u1ec7n \u0111i\u1ec1u n\u00e0y:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">use App\\Rules\\ZxcvbnRule;\r\n<\/span>\r\n\r\n<span style=\"font-weight: 400;\">Password::defaults(function () {<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0$rule = Password::min(8)-&gt;rules([new ZxcvbnRule]);<\/span>\r\n\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\/\/ ...<\/span>\r\n\r\n<span style=\"font-weight: 400;\">});<\/span><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Cau_hoi_thuong_gap_ve_Laravel_Validation\"><\/span><b>C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 Laravel Validation<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>Laravel Validation l\u00e0 g\u00ec?\u00a0<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Laravel Validation l\u00e0 m\u1ed9t t\u00ednh n\u0103ng t\u00edch h\u1ee3p s\u1eb5n trong framework Laravel gi\u00fap b\u1ea1n ki\u1ec3m tra v\u00e0 x\u00e1c th\u1ef1c d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o t\u1eeb ng\u01b0\u1eddi d\u00f9ng, \u0111\u1ea3m b\u1ea3o d\u1eef li\u1ec7u h\u1ee3p l\u1ec7 tr\u01b0\u1edbc khi \u0111\u1ebfn b\u01b0\u1edbc x\u1eed l\u00fd ti\u1ebfp theo.<\/span><\/p>\n<h3><b>C\u00f3 th\u1ec3 t\u00f9y ch\u1ec9nh th\u00f4ng b\u00e1o l\u1ed7i cho c\u00e1c quy t\u1eafc Laravel Validation kh\u00f4ng?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">C\u00f3, b\u1ea1n ho\u00e0n to\u00e0n c\u00f3 th\u1ec3 t\u00f9y ch\u1ec9nh c\u00e1c th\u00f4ng b\u00e1o l\u1ed7i cho c\u00e1c quy t\u1eafc validation trong Laravel. B\u1ea1n c\u00f3 th\u1ec3 th\u1ef1c hi\u1ec7n \u0111i\u1ec1u n\u00e0y b\u1eb1ng hai c\u00e1ch:<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">Truy\u1ec1n m\u1ea3ng ch\u1ee9a c\u00e1c th\u00f4ng b\u00e1o l\u1ed7i t\u00f9y ch\u1ec9nh l\u00e0 tham s\u1ed1 th\u1ee9 ba cho ph\u01b0\u01a1ng th\u1ee9c validate.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng ph\u01b0\u01a1ng th\u1ee9c messages tr\u00ean facade Validator \u0111\u1ec3 thi\u1ebft l\u1eadp c\u00e1c th\u00f4ng b\u00e1o l\u1ed7i t\u00f9y ch\u1ec9nh cho c\u00e1c tr\u01b0\u1eddng c\u1ee5 th\u1ec3.<\/span><\/li>\n<\/ul>\n<h3><b>L\u00e0m th\u1ebf n\u00e0o \u0111\u1ec3 ki\u1ec3m th\u1eed c\u00e1c quy t\u1eafc Laravel Validation?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Laravel cung c\u1ea5p m\u1ed9t l\u1edbp Validator t\u00edch h\u1ee3p s\u1eb5n \u0111\u1ec3 ki\u1ec3m th\u1eed c\u00e1c quy t\u1eafc Laravel Validation. B\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng c\u00e1c ph\u01b0\u01a1ng th\u1ee9c sau:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">passes: Ki\u1ec3m tra xem d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o c\u00f3 v\u01b0\u1ee3t qua t\u1ea5t c\u1ea3 c\u00e1c quy t\u1eafc kh\u00f4ng. Ph\u01b0\u01a1ng th\u1ee9c n\u00e0y tr\u1ea3 v\u1ec1 true n\u1ebfu d\u1eef li\u1ec7u h\u1ee3p l\u1ec7, false n\u1ebfu kh\u00f4ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">fails: Ki\u1ec3m tra xem c\u00f3 b\u1ea5t k\u1ef3 quy t\u1eafc n\u00e0o kh\u00f4ng v\u01b0\u1ee3t qua hay kh\u00f4ng. Ph\u01b0\u01a1ng th\u1ee9c n\u00e0y tr\u1ea3 v\u1ec1 true n\u1ebfu c\u00f3 l\u1ed7i validation, false n\u1ebfu kh\u00f4ng.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Ngo\u00e0i ra, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng facade Validator trong c\u00e1c b\u00e0i ki\u1ec3m tra \u0111\u01a1n v\u1ecb (unit test) \u0111\u1ec3 ki\u1ec3m th\u1eed c\u00e1c quy t\u1eafc validation.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Tong_ket_Laravel_Validation\"><\/span><b>T\u1ed5ng k\u1ebft Laravel Validation<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Laravel Validation \u0111\u00f3ng vai tr\u00f2 v\u00f4 c\u00f9ng quan tr\u1ecdng trong vi\u1ec7c b\u1ea3o m\u1eadt v\u00e0 \u0111\u1ea3m b\u1ea3o t\u00ednh ch\u00ednh x\u00e1c cho d\u1eef li\u1ec7u, \u0111\u1ea3m b\u1ea3o d\u1eef li\u1ec7u tu\u00e2n th\u1ee7 theo c\u00e1c quy t\u1eafc do b\u1ea1n \u0111\u1eb7t ra. Laravel cung c\u1ea5p \u0111a d\u1ea1ng ph\u01b0\u01a1ng th\u1ee9c ki\u1ec3m tra d\u1eef li\u1ec7u, gi\u00fap b\u1ea1n d\u1ec5 d\u00e0ng qu\u1ea3n l\u00fd v\u00e0 ki\u1ec3m so\u00e1t d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o. Vi\u1ec7c n\u1eafm v\u1eefng c\u00e1ch t\u1ea1o v\u00e0 \u00e1p d\u1ee5ng c\u00e1c quy t\u1eafc Laravel validation kh\u00f4ng ch\u1ec9 gi\u00fap b\u1ea1n x\u00e2y d\u1ef1ng c\u00e1c \u1ee9ng d\u1ee5ng web an to\u00e0n h\u01a1n m\u00e0 c\u00f2n n\u00e2ng cao ch\u1ea5t l\u01b0\u1ee3ng m\u00e3 ngu\u1ed3n. Ngo\u00e0i ra, h\u00e3y ti\u1ebfp t\u1ee5c kh\u00e1m ph\u00e1 v\u00e0 t\u1eadn d\u1ee5ng c\u00e1c t\u00ednh n\u0103ng m\u1ea1nh m\u1ebd c\u1ee7a Laravel \u0111\u1ec3 ph\u00e1t tri\u1ec3n nh\u1eefng \u1ee9ng d\u1ee5ng web ch\u1ea5t l\u01b0\u1ee3ng cao.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Trong ph\u00e1t tri\u1ec3n \u1ee9ng d\u1ee5ng hi\u1ec7n \u0111\u1ea1i, vi\u1ec7c \u0111\u1ea3m b\u1ea3o d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o l\u00e0 h\u1ee3p l\u1ec7 v\u00e0 ch\u00ednh x\u00e1c l\u00e0 v\u1ea5n \u0111\u1ec1 quan tr\u1ecdng h\u00e0ng \u0111\u1ea7u. Laravel &#8211; m\u1ed9t framework PHP ph\u1ed5 bi\u1ebfn, cung c\u1ea5p nhi\u1ec1u ph\u01b0\u01a1ng th\u1ee9c validation (ki\u1ec3m tra d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o) m\u1ea1nh m\u1ebd v\u00e0 to\u00e0n di\u1ec7n. B\u00e0i vi\u1ebft n\u00e0y s\u1ebd [&hellip;]<\/p>\n","protected":false},"author":205,"featured_media":74737,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_gspb_post_css":"","footnotes":""},"categories":[109,10105],"tags":[],"class_list":["post-74488","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chuyen-mon-it","category-tai-lieu-php"],"blocksy_meta":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.8 (Yoast SEO v27.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Laravel Validation: Chi ti\u1ebft c\u00e1c quy t\u1eafc v\u00e0 c\u00e1ch \u00e1p d\u1ee5ng hi\u1ec7u qu\u1ea3 - ITviec Blog<\/title>\n<meta name=\"description\" content=\"B\u00e0i vi\u1ebft t\u1ed5ng h\u1ee3p c\u00e1ch t\u1ea1o v\u00e0 \u00e1p d\u1ee5ng hi\u1ec7u qu\u1ea3 Laravel validation, t\u1eeb c\u00e1c quy t\u1eafc x\u00e1c th\u1ef1c c\u00f3 s\u1eb5n \u0111\u1ebfn t\u1ea1o ra c\u00e1c quy t\u1eafc t\u00f9y ch\u1ec9nh.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Laravel Validation: Chi ti\u1ebft c\u00e1c quy t\u1eafc v\u00e0 c\u00e1ch \u00e1p d\u1ee5ng hi\u1ec7u qu\u1ea3\" \/>\n<meta property=\"og:description\" content=\"Trong ph\u00e1t tri\u1ec3n \u1ee9ng d\u1ee5ng hi\u1ec7n \u0111\u1ea1i, vi\u1ec7c \u0111\u1ea3m b\u1ea3o d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o l\u00e0 h\u1ee3p l\u1ec7 v\u00e0 ch\u00ednh x\u00e1c l\u00e0 v\u1ea5n \u0111\u1ec1 quan tr\u1ecdng h\u00e0ng \u0111\u1ea7u. Laravel - m\u1ed9t framework PHP ph\u1ed5\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/\" \/>\n<meta property=\"og:site_name\" content=\"ITviec Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ITviec\" \/>\n<meta property=\"article:published_time\" content=\"2024-06-27T07:31:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/06\/Laravel-Validation-thumbnail-vippro.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1500\" \/>\n\t<meta property=\"og:image:height\" content=\"790\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"H\u00e0 My\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ITviec\" \/>\n<meta name=\"twitter:site\" content=\"@ITviec\" \/>\n<meta name=\"twitter:label1\" content=\"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi\" \/>\n\t<meta name=\"twitter:data1\" content=\"H\u00e0 My\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data2\" content=\"39 ph\u00fat\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Laravel Validation: Chi ti\u1ebft c\u00e1c quy t\u1eafc v\u00e0 c\u00e1ch \u00e1p d\u1ee5ng hi\u1ec7u qu\u1ea3 - ITviec Blog","description":"B\u00e0i vi\u1ebft t\u1ed5ng h\u1ee3p c\u00e1ch t\u1ea1o v\u00e0 \u00e1p d\u1ee5ng hi\u1ec7u qu\u1ea3 Laravel validation, t\u1eeb c\u00e1c quy t\u1eafc x\u00e1c th\u1ef1c c\u00f3 s\u1eb5n \u0111\u1ebfn t\u1ea1o ra c\u00e1c quy t\u1eafc t\u00f9y ch\u1ec9nh.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/","og_locale":"vi_VN","og_type":"article","og_title":"Laravel Validation: Chi ti\u1ebft c\u00e1c quy t\u1eafc v\u00e0 c\u00e1ch \u00e1p d\u1ee5ng hi\u1ec7u qu\u1ea3","og_description":"Trong ph\u00e1t tri\u1ec3n \u1ee9ng d\u1ee5ng hi\u1ec7n \u0111\u1ea1i, vi\u1ec7c \u0111\u1ea3m b\u1ea3o d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o l\u00e0 h\u1ee3p l\u1ec7 v\u00e0 ch\u00ednh x\u00e1c l\u00e0 v\u1ea5n \u0111\u1ec1 quan tr\u1ecdng h\u00e0ng \u0111\u1ea7u. Laravel - m\u1ed9t framework PHP ph\u1ed5","og_url":"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/","og_site_name":"ITviec Blog","article_publisher":"https:\/\/www.facebook.com\/ITviec","article_published_time":"2024-06-27T07:31:12+00:00","og_image":[{"width":1500,"height":790,"url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/06\/Laravel-Validation-thumbnail-vippro.jpg","type":"image\/jpeg"}],"author":"H\u00e0 My","twitter_card":"summary_large_image","twitter_creator":"@ITviec","twitter_site":"@ITviec","twitter_misc":{"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi":"H\u00e0 My","\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"39 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/#article","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/"},"author":{"name":"H\u00e0 My","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/7bd099db44e5079508c9b7e8c0161e3c"},"headline":"Laravel Validation: Chi ti\u1ebft c\u00e1c quy t\u1eafc v\u00e0 c\u00e1ch \u00e1p d\u1ee5ng hi\u1ec7u qu\u1ea3","datePublished":"2024-06-27T07:31:12+00:00","mainEntityOfPage":{"@id":"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/"},"wordCount":10939,"publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"image":{"@id":"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/06\/Laravel-Validation-thumbnail-vippro.jpg","articleSection":["Chuy\u00ean m\u00f4n IT","T\u00e0i li\u1ec7u PHP"],"inLanguage":"vi"},{"@type":"WebPage","@id":"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/","url":"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/","name":"Laravel Validation: Chi ti\u1ebft c\u00e1c quy t\u1eafc v\u00e0 c\u00e1ch \u00e1p d\u1ee5ng hi\u1ec7u qu\u1ea3 - ITviec Blog","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/#primaryimage"},"image":{"@id":"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/06\/Laravel-Validation-thumbnail-vippro.jpg","datePublished":"2024-06-27T07:31:12+00:00","description":"B\u00e0i vi\u1ebft t\u1ed5ng h\u1ee3p c\u00e1ch t\u1ea1o v\u00e0 \u00e1p d\u1ee5ng hi\u1ec7u qu\u1ea3 Laravel validation, t\u1eeb c\u00e1c quy t\u1eafc x\u00e1c th\u1ef1c c\u00f3 s\u1eb5n \u0111\u1ebfn t\u1ea1o ra c\u00e1c quy t\u1eafc t\u00f9y ch\u1ec9nh.","breadcrumb":{"@id":"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/#primaryimage","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/06\/Laravel-Validation-thumbnail-vippro.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/06\/Laravel-Validation-thumbnail-vippro.jpg","width":1500,"height":790,"caption":"laravel validation - itviec blog"},{"@type":"BreadcrumbList","@id":"https:\/\/itviec.com\/blog\/laravel-validation-la-gi\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Chuy\u00ean m\u00f4n IT","item":"https:\/\/itviec.com\/blog\/chuyen-mon-it\/"},{"@type":"ListItem","position":2,"name":"Laravel Validation: Chi ti\u1ebft c\u00e1c quy t\u1eafc v\u00e0 c\u00e1ch \u00e1p d\u1ee5ng hi\u1ec7u qu\u1ea3"}]},{"@type":"WebSite","@id":"https:\/\/itviec.com\/blog\/#website","url":"https:\/\/itviec.com\/blog\/","name":"ITviec Blog","description":"IT Jobs &amp; People in Vietnam","publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itviec.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":"Organization","@id":"https:\/\/itviec.com\/blog\/#organization","name":"ITviec","url":"https:\/\/itviec.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","width":1800,"height":1800,"caption":"ITviec"},"image":{"@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ITviec","https:\/\/x.com\/ITviec","https:\/\/www.linkedin.com\/company\/itviec","https:\/\/www.youtube.com\/channel\/UCYthAQ3bcGr57M_ag5gHDvQ"]},{"@type":"Person","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/7bd099db44e5079508c9b7e8c0161e3c","name":"H\u00e0 My","image":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/ha-my-author-e1709882319892-100x100.jpeg","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/ha-my-author-e1709882319892-100x100.jpeg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/ha-my-author-e1709882319892-100x100.jpeg","caption":"H\u00e0 My"},"url":"https:\/\/itviec.com\/blog\/author\/ha-my\/"}]}},"_links":{"self":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/74488","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/users\/205"}],"replies":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/comments?post=74488"}],"version-history":[{"count":0,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/74488\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media\/74737"}],"wp:attachment":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media?parent=74488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/categories?post=74488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/tags?post=74488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}