composer require "illuminate/database" composer require "illuminate/events" Config/Events.php use Illuminate\Database\Capsule\Manager as Capsule; use Illuminate\Events\Dispatcher; use Illuminate\Container\Container; function boostEloquent() { $capsule = new Capsule; $capsule->addConnection([ 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'database', 'username' => 'root', 'password' => 'password', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ]); // Set the event dispatcher used by Eloquent models... (optional) $capsule->setEventDispatcher(new Dispatcher(new Container)); // Make this Capsule instance available globally via static methods.

繼續閱讀

Golang Gin Api become Windows Service Use github.com/kardianos/service package main import ( "errors" "fmt" "io" "log" "net" "net/http" "os" "path/filepath" "strings" "time" "github.com/gin-gonic/gin" "github.com/joho/godotenv" "github.com/kardianos/service" ) // Process Windows Service // github.com/kardianos/service var logger service.Logger type program struct{} func (p *program) Start(s service.Service) error { // Start should not block. Do the actual work async. go p.run() return nil } func (p *program) Stop(s service.Service) error { // Stop should not block.

繼續閱讀

Modify ModelTrait file at \App\Traits namespace App\Traits; trait ModelTrait { // fetaure Maybe belongsTo // get result but not effect this, keep this ORM status public function newSelfObject() { return $this->db->query($this->builder->getCompiledSelect(false)); } // copy self object return ORM Object public function cso() { $class_name = get_class($this); $class_new_object = (new $class_name); $class_new_object->builder = clone $this->builder; return $class_new_object; } public function hasOne($class, $relation_primary_key=null, $primary_key=null) { return $class->where($relation_primary_key ?? $this->primaryKey, $this->newSelfObject()->getRowArray()[$primary_key ?

繼續閱讀

Add ModelTrait file at \App\Traits namespace App\Traits; trait ModelTrait { // fetaure Maybe belongsTo // get result but not effect this, keep this ORM status public function newSelfObject() { return $this->db->query($this->builder->getCompiledSelect(false)); } public function hasOne($class, $relation_primary_key=null, $primary_key=null) { return $class->where($relation_primary_key ?? $this->primaryKey, $this->newSelfObject()->getRowArray()[$primary_key ?? $this->primaryKey] ?? ''); } // whereIn If can't get records, return null. Usually use primaryKey cloud happen public function hasMany($class, $relation_primary_key=null, $primary_key=null) { $temp = array_column($this->newSelfObject()->getResult(), $primary_key ?

繼續閱讀

https://codereview.stackexchange.com/questions/80080/aggregate-array-values-into-ranges // Output: // Array ( // [0] => Array ( [0] => 1, [1] => 2, [2] => 3, [3] => 4, [4] => 5, [5] => 6 ) // [1] => Array ( [0] => 10, [1] => 11, [2] => 12, [3] => 13 ) // [2] => Array ( [0] => 20 ) // [3] => Array ( [0] => 24 ) // ) static function GetRanges1( $aNumbers ) { $aNumbers = array_unique( $aNumbers ); sort( $aNumbers ); $aGroups = array(); for( $i = 0; $i < count( $aNumbers ); $i++ ) { if( $i > 0 && ( $aNumbers[$i-1] == $aNumbers[$i] - 1 )) array_push( $aGroups[count($aGroups)-1], $aNumbers[$i] ); else array_push( $aGroups, array( $aNumbers[$i] )); } return $aGroups; } // Output: Array ( [0] => 1-6, [1] => 10-13, [2] => 20, [3] => 24 ) static function GetRanges2( $aNumbers ) { $aNumbers = array_unique( $aNumbers ); sort( $aNumbers ); $aGroups = array(); for( $i = 0; $i < count( $aNumbers ); $i++ ) { if( $i > 0 && ( $aNumbers[$i-1] == $aNumbers[$i] - 1 )) array_push( $aGroups[count($aGroups)-1], $aNumbers[$i] ); else array_push( $aGroups, array( $aNumbers[$i] )); } $aRanges = array(); foreach( $aGroups as $aGroup ) { if( count( $aGroup ) == 1 ) $aRanges[] = $aGroup[0]; else $aRanges[] = $aGroup[0] .

繼續閱讀

作者的圖片

Sue boy

Sueboy Can support You

CIO

Taiwan