php

Validator’s form validation in laravel

========================== $validator = Validator::make($request->all(), [ ‘nickname’ => ‘required|max:8|string’, ‘signature’ => ‘string|max:30’, ‘gender’ => ‘ integer’, ‘height’ => ‘ digits_between:50,300’, ‘weight’ => ‘ integer|min:2|max:3’, ‘birth_date’ => ‘date’, ‘city’ => ‘string’, ‘order_number’ => ‘exists:orders,order_number’, ‘openid’ => ‘exists:orders,openid’, ‘activity_id’ => ‘required’ ]); if ($validator->fails()) { return $this->responseForJson(ERR_ACCESS_DEN, $validator->errors()); } accepted Validation will only pass if the field value …

Validator’s form validation in laravel Read More »

Understanding of PHP stack data segment code segment

Understanding of PHP stack data segment code segment Stack: basic data type (roughly understood as space A, where the number 8 is stored) Heap: object created by new Code segment: function, running code Number segment: string constant, global variable, static variable, etc. Objects in PHP are the same as integers and floating-point types. They are …

Understanding of PHP stack data segment code segment Read More »

txt file into mysql

LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name' [REPLACE | IGNORE] INTO TABLE tbl_name [CHARACTER SET charset_name] [{FIELDS | COLUMNS} [TERMINATED BY 'string'] [[OPTIONALLY] ENCLOSED BY 'char'] [ESCAPED BY 'char'] ] [LINES [STARTING BY 'string'] [TERMINATED BY 'string'] ] [IGNORE number LINES] [(col_name_or_user_var,…)] [SET col_name = expr,…] MySQL usually uses the [insert] statement to write …

txt file into mysql Read More »

ThinkPHP5 cannot parse the received json datadata error

When ThinkPHP receives the JSON data sent by the front end, it uses the json_decodeparsed data null. Reason: ThinkPHP will filter the received data by default, so after the JSON [string] is filtered, an error occurs. Solution: Use the following methods to receive data, raw data (unfiltered) // Get all variables of the current request …

ThinkPHP5 cannot parse the received json datadata error Read More »

The method of modifying the enumeration type enum in the laravel framework

public function up () { // Just add this sentence Schema::getConnection()->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping( 'enum' , 'string' ); Schema::table('contract_records', function (Blueprint $table) { $table->string('level')->change(); }); } [Schema]::getConnection()->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping(‘enum’, ‘string’); public function up () { // Just add this sentence Schema::getConnection()->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping( 'enum' , 'string' ); Schema::table('contract_records', function (Blueprint $table) { $table->string('level')->change(); }); } This method may then report an error, …

The method of modifying the enumeration type enum in the laravel framework Read More »

PHP infinite classification recursive implementation, infinite classification introduction implementation, performance gap

Performance gap introduced by php infinite classification recursion and infinite classification Reference method: function generateTree ($array) { //The first step is to construct data $items = array (); foreach ($array as $value){ $items[$value['id']] = $value; } //The second part traverses the data to generate a tree structure $tree = array (); $level = 0; foreach($items …

PHP infinite classification recursive implementation, infinite classification introduction implementation, performance gap Read More »

PHP closure function and closure function callback

PHP [closure] function and closure function callback A function without a name becomes an anonymous function eg: $sum = function($num1,$num2){ return $num1+$num2; }; //Anonymous function call echo $sum( 1 , 2 ); [Callback] method of anonymous function Callback — call another function in one function eg: function sum($n1,$n2,$c){ return $c($n,$n2); } $res = sum(1,2,function($n1,$n2)){ return …

PHP closure function and closure function callback Read More »

PHP – Laravel view template (blade.php) loop convenience

web.phproute parameter Route::get( ‘req’ , function () { // Json parameter $users = [ [‘id’=>1, ‘name’=>’test’], [‘id’=>2, ‘name’=>’dzm’], [‘id’=>3, ‘name’=>’xyq’] ]; return view(‘index’)->with([‘users’=>$users]); }); Commonly used loops for (blade.php)view templates are:for 1、@foreach <div>Method 1:</div> @foreach ($users as $user) <div>{{ $user['name'] }}</div> @endforeach</p> <hr> <p><div>Method 2:</div> @foreach ($users as $key=>$value) <div>{{ $key }} – {{ $value['name'] …

PHP – Laravel view template (blade.php) loop convenience Read More »

PHP – Laravel Ternary Operations

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta > <title>Document</title> </head> <body> <!– The following methods are equivalent to <?php echo isset($name) ? $name : 'default' ?> –> <!– Most commonly used –> < div > {{ $data['id'] ? $data['id'] : 'no ID' }} </ div > <!– laravel normal use –> …

PHP – Laravel Ternary Operations Read More »