Laravel Tips-Multilingual prompts, introduction of common functions, URL ignore case ____ function

Source: Internet
Author: User
Tags autoload
Create a laravel5.1 project easy_grouping.
Composer Create-project Laravel/laravel easy_grouping 5.1.*

1. Multi-language TipsCreate a new directory ZH-CN in the Resources-lang directory, creating tip.php, as follows
<?php return
[' => ' successful operation '];
Modify config/app.php
' Locale ' => ' ZH-CN ',
In the mouth of the answer
Echo Trans (' tip.200 ');
Output "Operation succeeded"
2. Introducing Common functionsCreate a helper directory in the app directory and create a common_functions.php that reads as follows
<?php
function Test ()
{
echo ' common funciton include succeed ';
}
Increase in Composer.json
"AutoLoad": {
    "files": [
      "app/helper/common_funtions.php"
    ]
  }
Command-line execution
Composer Dump-autoload
The test () function can be used globally.
3.url Ignore CaseUnder the helper folder created above, create a caseinsensitiveurivalidator.php that reads
<?php namespace App\helper;

Use Illuminate\http\request;
Use Illuminate\routing\route;
Use Illuminate\routing\matching\validatorinterface;

Class Caseinsensitiveurivalidator implements Validatorinterface
{public
    function matches (Route $route, Request $request)
    {
        $path = $request->path () = = '/'? '/': '/'. $request->path ();
        Return Preg_match (preg_replace ('/$/', ' I ', $route->getcompiled ()->getregex ()), Rawurldecode ($path));
    }
Introduced in the routes.php
Use Illuminate\routing\route as Illuminateroute;
Use App\helper\caseinsensitiveurivalidator;
Use Illuminate\routing\matching\urivalidator;

$validators = Illuminateroute::getvalidators ();
$validators [] = new Caseinsensitiveurivalidator;
Illuminateroute:: $validators = Array_filter ($validators, function ($validator) {return
    Get_class ($validator)!= Urivalidator::class;
});














Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.