{"type":"rich","version":"1.0","provider_name":"phorkie","provider_url":"https:\/\/p.cweiske.de\/","title":"Laravel validation error messages: show locale-specific date","author_name":"Christian Weiske","cache_age":86400,"width":900,"height":900,"html":"<!-- embedding all files of https:\/\/p.cweiske.de\/624 -->\n<link rel=\"stylesheet\" href=\"https:\/\/p.cweiske.de\/css\/embed.css\"\/>\n<div class=\"phork\" id=\"624\">\n    <div class=\"phork-file\">\n <div class=\"phork-content\">\n  <style type=\"text\/css\">\/**\n * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2014 Benny Baumann\n * (http:\/\/qbnz.com\/highlighter\/ and http:\/\/geshi.org\/)\n *\/\n.php .de1, .php .de2 {font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;}\n.php  {font-family:monospace;}\n.php .imp {font-weight: bold; color: red;}\n.php li, .php .li1 {color: #DDD;}\n.php .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}\n.php .kw1 {color: #b1b100;}\n.php .kw2 {color: #000000; font-weight: bold;}\n.php .kw3 {color: #990000;}\n.php .kw4 {color: #009900; font-weight: bold;}\n.php .co1 {color: #666666; font-style: italic;}\n.php .co2 {color: #666666; font-style: italic;}\n.php .co3 {color: #0000cc; font-style: italic;}\n.php .co4 {color: #009933; font-style: italic;}\n.php .coMULTI {color: #666666; font-style: italic;}\n.php .es0 {color: #000099; font-weight: bold;}\n.php .es1 {color: #000099; font-weight: bold;}\n.php .es2 {color: #660099; font-weight: bold;}\n.php .es3 {color: #660099; font-weight: bold;}\n.php .es4 {color: #006699; font-weight: bold;}\n.php .es5 {color: #006699; font-weight: bold; font-style: italic;}\n.php .es6 {color: #009933; font-weight: bold;}\n.php .es_h {color: #000099; font-weight: bold;}\n.php .br0 {color: #009900;}\n.php .sy0 {color: #339933;}\n.php .sy1 {color: #000000; font-weight: bold;}\n.php .st0 {color: #0000ff;}\n.php .st_h {color: #0000ff;}\n.php .nu0 {color: #cc66cc;}\n.php .nu8 {color: #208080;}\n.php .nu12 {color: #208080;}\n.php .nu19 {color:#800080;}\n.php .me1 {color: #004000;}\n.php .me2 {color: #004000;}\n.php .re0 {color: #000088;}\n.php span.xtra { display:block; }\n<\/style><div class=\"code\"><table class=\"php\"><tbody><tr class=\"li1\"><td class=\"ln\"><pre class=\"de1\">1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n<\/pre><\/td><td class=\"de1\"><pre class=\"de1\">&#160; &#160; &#160; &#160; \\Illuminate\\Support\\Facades\\Validator<span class=\"sy0\">::<\/span><span class=\"me2\">replacer<\/span><span class=\"br0\">&#40;<\/span>\n&#160; &#160; &#160; &#160; &#160; &#160; <span class=\"st_h\">'after'<\/span><span class=\"sy0\">,<\/span> LocalDateFormatReplacer<span class=\"sy0\">::<\/span><span class=\"kw2\">class<\/span>\n&#160; &#160; &#160; &#160; <span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span>\n&#160; &#160; &#160; &#160; \\Illuminate\\Support\\Facades\\Validator<span class=\"sy0\">::<\/span><span class=\"me2\">replacer<\/span><span class=\"br0\">&#40;<\/span>\n&#160; &#160; &#160; &#160; &#160; &#160; <span class=\"st_h\">'after_or_equal'<\/span><span class=\"sy0\">,<\/span> LocalDateFormatReplacer<span class=\"sy0\">::<\/span><span class=\"kw2\">class<\/span>\n&#160; &#160; &#160; &#160; <span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span>\n&#160; &#160; &#160; &#160; \\Illuminate\\Support\\Facades\\Validator<span class=\"sy0\">::<\/span><span class=\"me2\">replacer<\/span><span class=\"br0\">&#40;<\/span>\n&#160; &#160; &#160; &#160; &#160; &#160; <span class=\"st_h\">'before'<\/span><span class=\"sy0\">,<\/span> LocalDateFormatReplacer<span class=\"sy0\">::<\/span><span class=\"kw2\">class<\/span>\n&#160; &#160; &#160; &#160; <span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span>\n&#160; &#160; &#160; &#160; \\Illuminate\\Support\\Facades\\Validator<span class=\"sy0\">::<\/span><span class=\"me2\">replacer<\/span><span class=\"br0\">&#40;<\/span>\n&#160; &#160; &#160; &#160; &#160; &#160; <span class=\"st_h\">'before_or_equal'<\/span><span class=\"sy0\">,<\/span> LocalDateFormatReplacer<span class=\"sy0\">::<\/span><span class=\"kw2\">class<\/span>\n&#160; &#160; &#160; &#160; <span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span>\n&#160;<\/pre><\/td><\/tr><\/tbody><\/table><\/div>\n <\/div>\n <div class=\"phork-meta\">\n  <a href=\"https:\/\/p.cweiske.de\/624\/rev-raw\/c77a09781b7c7bfb653381e561c2cd89001a0d43\/AppServiceProvider.php\" style=\"float: right\">view raw source<\/a>\n  <a href=\"https:\/\/p.cweiske.de\/624#AppServiceProvider.php\">AppServiceProvider.php<\/a>\n <\/div>\n<\/div>\n    <div class=\"phork-file\">\n <div class=\"phork-content\">\n  <style type=\"text\/css\">\/**\n * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2014 Benny Baumann\n * (http:\/\/qbnz.com\/highlighter\/ and http:\/\/geshi.org\/)\n *\/\n.php .de1, .php .de2 {font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;}\n.php  {font-family:monospace;}\n.php .imp {font-weight: bold; color: red;}\n.php li, .php .li1 {color: #DDD;}\n.php .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}\n.php .kw1 {color: #b1b100;}\n.php .kw2 {color: #000000; font-weight: bold;}\n.php .kw3 {color: #990000;}\n.php .kw4 {color: #009900; font-weight: bold;}\n.php .co1 {color: #666666; font-style: italic;}\n.php .co2 {color: #666666; font-style: italic;}\n.php .co3 {color: #0000cc; font-style: italic;}\n.php .co4 {color: #009933; font-style: italic;}\n.php .coMULTI {color: #666666; font-style: italic;}\n.php .es0 {color: #000099; font-weight: bold;}\n.php .es1 {color: #000099; font-weight: bold;}\n.php .es2 {color: #660099; font-weight: bold;}\n.php .es3 {color: #660099; font-weight: bold;}\n.php .es4 {color: #006699; font-weight: bold;}\n.php .es5 {color: #006699; font-weight: bold; font-style: italic;}\n.php .es6 {color: #009933; font-weight: bold;}\n.php .es_h {color: #000099; font-weight: bold;}\n.php .br0 {color: #009900;}\n.php .sy0 {color: #339933;}\n.php .sy1 {color: #000000; font-weight: bold;}\n.php .st0 {color: #0000ff;}\n.php .st_h {color: #0000ff;}\n.php .nu0 {color: #cc66cc;}\n.php .nu8 {color: #208080;}\n.php .nu12 {color: #208080;}\n.php .nu19 {color:#800080;}\n.php .me1 {color: #004000;}\n.php .me2 {color: #004000;}\n.php .re0 {color: #000088;}\n.php span.xtra { display:block; }\n<\/style><div class=\"code\"><table class=\"php\"><tbody><tr class=\"li1\"><td class=\"ln\"><pre class=\"de1\">1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n<\/pre><\/td><td class=\"de1\"><pre class=\"de1\"><span class=\"kw2\">&lt;?php<\/span>\n<span class=\"kw2\">namespace<\/span> App\\Validators<span class=\"sy0\">;<\/span>\n&#160;\n<span class=\"co4\">\/**<\/span>\n<span class=\"co4\">&#160;* Replace the :date attribute value in a validation error message with the<\/span>\n<span class=\"co4\">&#160;* locale-specific date format.<\/span>\n<span class=\"co4\">&#160;*<\/span>\n<span class=\"co4\">&#160;* Registered in AppServiceProvider.<\/span>\n<span class=\"co4\">&#160;*<\/span>\n<span class=\"co4\">&#160;* @author Christian Weiske &lt;weiske@mogic.com&gt;<\/span>\n<span class=\"co4\">&#160;*\/<\/span>\n<span class=\"kw2\">class<\/span> LocalDateFormatReplacer\n<span class=\"br0\">&#123;<\/span>\n&#160; &#160; <span class=\"co4\">\/**<\/span>\n<span class=\"co4\">&#160; &#160; &#160;* Replace the :date attribute value with the local date format.<\/span>\n<span class=\"co4\">&#160; &#160; &#160;*<\/span>\n<span class=\"co4\">&#160; &#160; &#160;* @param string $message &#160; &#160;Message with &quot;:date&quot; placeholder<\/span>\n<span class=\"co4\">&#160; &#160; &#160;* @param string $attribute &#160;Name of attribute (e.g. &quot;contract_start&quot;)<\/span>\n<span class=\"co4\">&#160; &#160; &#160;* @param string $rule &#160; &#160; &#160; Name of the rule (e.g. &quot;before_or_equals&quot;)<\/span>\n<span class=\"co4\">&#160; &#160; &#160;* @param array &#160;$parameters Attributes to dipsplay. Key 0 is the date.<\/span>\n<span class=\"co4\">&#160; &#160; &#160;* @param object $validator &#160;Validator instance<\/span>\n<span class=\"co4\">&#160; &#160; &#160;*<\/span>\n<span class=\"co4\">&#160; &#160; &#160;* @return string Final message with replaced :date<\/span>\n<span class=\"co4\">&#160; &#160; &#160;*\/<\/span>\n&#160; &#160; <span class=\"kw2\">function<\/span> replace<span class=\"br0\">&#40;<\/span><span class=\"re0\">$message<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">$attribute<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">$rule<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">$parameters<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">$validator<\/span><span class=\"br0\">&#41;<\/span>\n&#160; &#160; <span class=\"br0\">&#123;<\/span>\n&#160; &#160; &#160; &#160; <span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span><a href=\"http:\/\/www.php.net\/strtotime\"><span class=\"kw3\">strtotime<\/span><\/a><span class=\"br0\">&#40;<\/span><span class=\"re0\">$parameters<\/span><span class=\"br0\">&#91;<\/span><span class=\"nu0\">0<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"sy0\">===<\/span> <span class=\"kw4\">false<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span>\n&#160; &#160; &#160; &#160; &#160; &#160; <span class=\"co1\">\/\/a label, not a time string<\/span>\n&#160; &#160; &#160; &#160; &#160; &#160; <span class=\"re0\">$date<\/span> <span class=\"sy0\">=<\/span> <span class=\"re0\">$validator<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">getDisplayableAttribute<\/span><span class=\"br0\">&#40;<\/span><span class=\"re0\">$parameters<\/span><span class=\"br0\">&#91;<\/span><span class=\"nu0\">0<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span>\n&#160; &#160; &#160; &#160; <span class=\"br0\">&#125;<\/span> <span class=\"kw1\">else<\/span> <span class=\"br0\">&#123;<\/span>\n&#160; &#160; &#160; &#160; &#160; &#160; <span class=\"re0\">$date<\/span> <span class=\"sy0\">=<\/span> reos_date<span class=\"br0\">&#40;<\/span><span class=\"re0\">$parameters<\/span><span class=\"br0\">&#91;<\/span><span class=\"nu0\">0<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span>\n&#160; &#160; &#160; &#160; <span class=\"br0\">&#125;<\/span>\n&#160;\n&#160; &#160; &#160; &#160; <span class=\"kw1\">return<\/span> <a href=\"http:\/\/www.php.net\/str_replace\"><span class=\"kw3\">str_replace<\/span><\/a><span class=\"br0\">&#40;<\/span><span class=\"st_h\">':date'<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">$date<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">$message<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span>\n&#160; &#160; <span class=\"br0\">&#125;<\/span>\n<span class=\"br0\">&#125;<\/span>\n<span class=\"sy1\">?&gt;<\/span>\n&#160;\n&#160;<\/pre><\/td><\/tr><\/tbody><\/table><\/div>\n <\/div>\n <div class=\"phork-meta\">\n  <a href=\"https:\/\/p.cweiske.de\/624\/rev-raw\/c77a09781b7c7bfb653381e561c2cd89001a0d43\/LocalDateFormatReplacer.php\" style=\"float: right\">view raw source<\/a>\n  <a href=\"https:\/\/p.cweiske.de\/624#LocalDateFormatReplacer.php\">LocalDateFormatReplacer.php<\/a>\n <\/div>\n<\/div>\n    <div class=\"phork-file\">\n <div class=\"phork-content\">\n  <div class=\"code\"><pre class=\"txt\">\r\n\r\nhttps:\/\/laravel.com\/docs\/5.5\/validation\r\n\r\n\r\nkeywords:\r\n- laravel validation date format locale\r\n- laravel validation error message adjust data\r\n- customize error message data\r\n\r\n\r\nvendor\/laravel\/framework\/src\/Illuminate\/Validation\/Validator.php\r\nvendor\/laravel\/framework\/src\/Illuminate\/Validation\/Concerns\/FormatsMessages.php\r\nmakeReplacements\r\n\r\nReplacesAttributes.php\r\n  replaceBefore\r\ngetDisplayableAttribute\r\n\r\nac4178d92561bd46dd8640cd5825b41d2a4759c3\r\n\r\n\r\naddReplacer\r\n<\/pre><\/div>\n\n <\/div>\n <div class=\"phork-meta\">\n  <a href=\"https:\/\/p.cweiske.de\/624\/rev-raw\/c77a09781b7c7bfb653381e561c2cd89001a0d43\/test.txt\" style=\"float: right\">view raw source<\/a>\n  <a href=\"https:\/\/p.cweiske.de\/624#test.txt\">test.txt<\/a>\n <\/div>\n<\/div>\n<\/div>\n"}
