laravel Production-ready

https://serversideup.net/open-source/spin/ Laravel sail https://laravel.com/docs/11.x/installation#choosing-your-sail-services shinsenter laravel https://github.com/shinsenter/php/pkgs/container/laravel

2024-08-28 · 1 min · 7 words · Me

php artisan config:cache

https://serversideup.net/open-source/docker-php/docs/laravel/laravel-automations#php-artisan-configcache This command caches all configuration files into a single file, which can then be quickly loaded by Laravel. Once the configuration is cache, the .env file will no longer be loaded.

2024-08-15 · 1 min · 32 words · Me

Two dimensional Array unique

$goods = [ 1 => [ 'id' => 12, 'price' => 77, ], 2 => [ 'id' => 43, 'price' => 855, ], 4 => [ 'id' => 34, 'price' => 1, ], ]; $goods_unique_ids_keys = array_keys(array_unique(array_column($goods, 'id'))); $goods_filter_datas = array_filter($goods, fn($key) => in_array($key, $goods_unique_ids_keys), ARRAY_FILTER_USE_KEY);

2024-02-20 · 1 min · 46 words · Me

Livewire form and outside form with button action maybe different your think

In liveiwre word some button action and alpine @click action be clicked, livewire 3 update (ajax) is different your think. Component public $test_input=1; public function tt() { info('tt'); info($this->test_input); } blade <div class="row row-cols-1 row-cols-md-3 g-4" x-data> <form wire:submit="tt"> <input type="text" wire:model='test_input'> <button type="submit">form type=submit</button> {{-- // update (ajax) --}} <button type="button">form type=button</button> {{-- // No update (ajax) --}} <button wire:click='tt; $wire.test_input=3;'>form wire:click</button> {{-- // update (ajax) and run twice --}} <button @click='$wire.tt; $wire.test_input=3;'>form @click</button> {{-- // update (ajax) and run twice --}} </form> <button type="submit">out form type=submit</button> {{-- // No update (ajax) --}} <button type="button">out form type=button</button> {{-- // No update (ajax) --}} <button wire:click='tt; $wire.test_input=3;'>out form wire:click</button> {{-- // update (ajax) --}} <button @click='$wire.tt; $wire.test_input=3;'>out form @click</button> {{-- // update (ajax) --}} </div> So be careful and try to understand ...

2023-12-31 · 1 min · 147 words · Me

Codeigniter 4 ORM relation By hand Part 2

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 ?? $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 ?? $this->primaryKey); return $class->whereIn($relation_primary_key ?? $this->primaryKey, empty($temp) ? [null] : $temp); } } App\Controllers\OrderListContriller.php ...

2022-12-29 · 1 min · 147 words · Me

Codeigniter 4 ORM relation By hand

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 ?? $this->primaryKey); return $class->whereIn($relation_primary_key ?? $this->primaryKey, empty($temp) ? [null] : $temp); } } How to use App\Models\Order.php class Order extends Model { use ModelTrait; protected $table = 'order'; protected $primaryKey = 'order_id'; public function members() { return $this->hasMany(new Member); // OR return $this->hasMany(new Member, 'id', 'member_id'); // id always use new Member, member_id use Order } App\Controllers\OrderListContriller.php ...

2022-11-22 · 1 min · 201 words · Me

SeckillSolution 秒殺 高并發 交易

https://github.com/qianshou/SeckillSolution https://blog.csdn.net/koastal/article/details/78995885 ===== https://blog.csdn.net/qq_38512763/article/details/118830903

2022-09-30 · 1 min · 4 words · Me

Aggregate array values into ranges

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] . '-' . $aGroup[count($aGroup)-1]; } return $aRanges; } // Output: 1~6,10~13,20,24 static function GetRanges3( $aNumbers, $headChar='' ) { $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[] = $headChar.$aGroup[0]; else $aRanges[] = $headChar.$aGroup[0] . '~' . $headChar.$aGroup[count($aGroup)-1]; } return implode( ',', $aRanges ); }

2022-09-23 · 2 min · 313 words · Me

[轉]PHP 8.2 Remove libmysql mysqli

https://m.facebook.com/story.php?story_fbid=10216824504164331&id=1815507975 《 PHP RFC: Remove support for libmysql from mysqli 》 » https://wiki.php.net/rfc/mysqli_support_for_libmysql PHP 核心開發團隊投票通過移除 mysqli 的 libmysql 支援,將於 PHP 8.2 正式生效。這項討論從農曆年前關注到年後,最終於 2022/2/5 全數投票通過。 對於一般 PHP 開發者是好事,不用再考慮 MySQL 是選擇 libmysql 還是 mysqlnd;面試時也減少面試官詢問兩者差異的比較 (不過現在很多面試官也不知道了)。 如果想瞭解 libmysql / mysqlnd 的優缺點,官方 RFC 也貼心地條列整理了。不過 RFC 裡沒提關於「License (授權)」的考量,特別在商業上。這也是 PHP 與 Python 及 Ruby 等社群有著不太一樣的生態考量。 Python 要連結 MySQL,通常選用 MySQL Connector 或 MySQLdb,但這兩者底層都依賴 libmysqlclient (MySQL C Library),而 libmysqlclient 的授權 [1] 主要採用 GPL-2.0,進而連帶影響了整體產品/專案的授權。 Ruby 要連結 MySQL,通常選用 mysql2,而其底層同樣依賴 libmysqlclient,有著同樣的潛在商業問題。 更重要的是 libmysqlclient 背後的公司是 Oracle。 ...

2022-02-07 · 1 min · 115 words · Me

zendesk opensource freescout

https://github.com/freescout-helpdesk/freescout

2021-03-12 · 1 min · word · Me

Laravel livewire have Big Problem!

When juse livewire at blade.php Must have Div At first. <div style="text-align: center"> <button wire:click="increment">+</button> <h1>{{ $count }}</h1> </div> + {{ $count }} {{ trans('global.add') }} {{ trans('cruds.order.title_singular') }}

2020-10-19 · 1 min · 29 words · Me

laravel livewire namespace

App/Http/Livewire/Orders.php``` namespace App\Http\Livewire; use Gate; use Livewire\Component; use Symfony\Component\HttpFoundation\Response; class Orders extends Component { public function render() { abort_if(Gate::denies(‘order_access’), Response::HTTP_FORBIDDEN, ‘403 Forbidden’); return view('livewire.order'); } } resources/views/livewire/order.blade.php @extends(’layouts.app’) @section(‘content’) @livewire(‘order.show’) @endsection App/Http/Livewire/Order/Show.php namespace App\Http\Livewire\Order; public function render() { abort_if(Gate::denies('order_access'), Response::HTTP_FORBIDDEN, '403 Forbidden'); $this->orders = Order::all(); // Order::where('owner_id', auth()->id())->get(); // 只能看自己 return view('livewire.order.show'); } resources/views/livewire/order/show.blade.php {{ virables }}

2020-10-19 · 1 min · 57 words · Me

laravel eloquent orm

 [one to one] Table: User, Phone Model: User Relation: return $this->hasOne(‘App\Phone’); Talbe Phone need have user_id. Auto use User id -> Phone user_id Table: User, Phone Model: Phone Relaion: return $this->belongsTo(‘App\User’); Table Phone need have user_id. Auto use User id -> User user_id [one to many] Table: Post, Comment Model: Post Relation: return $this->hasMany(‘App\Comment’); Table Comment need have post_id. Auto use Post id -> Comment post_id Table: Post, Comment Model: Comment ...

2020-10-16 · 1 min · 116 words · Me

livewire laravel route problem!

larvel 8 remove Providers/RouteServiceProvider.php namespace. Maybe you add back again. protected $namespace = 'App\Http\Controllers'; ... $this->routes(function () { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) ->group(base_path('routes/api.php')); Route::middleware('web') ->namespace($this->namespace) ->group(base_path('routes/web.php')); }); Add backup namespace then get problem for livewire. Every route just use App\Http|controllers ooxxooxxooxx. OLD Way web.php Route::resource('users', 'UsersController'); Route::delete('users/destroy', 'UsersController@massDestroy'); Get Error Route::resource('orders', 'livewire.order'); Route::resource('orders', 'livewire@order'); Route::view('orders', [\App\Http\Livewire\Order::class, 'render']); Maybe Way web.php Route::view('orders', 'livewire.order'); Files: \app\Http\Livewire\Order.php inside use return view('livewire.order'); \resources\views\livewire\order.blade.php Get Error Undefined variable: orders or other ooxxooxx Alwasy get this Error. ````````` ``` web.php Route::get('/admin/orders', [\App\Http\Livewire\Order::class, 'render']); Files: \app\Http\Livewire\Order.php And use return <<<'blade' blade; Get plain text @foreach($orders as o$key -> $permission Same Error. `````Beacuse view run first. Only create view then @livewire('') example: order and orderlist order view for fist(main) load page. orderlist be loaded by order view. order view have @livewire('orderlist'). https://stackoverflow.com/questions/64038485/laravel-livewire-components-or-controllers or just remove namespace ------------------------ Route::get(’/admin/orders’, \App\Http\Livewire\Order::class); ...

2020-10-15 · 1 min · 156 words · Me

php auth role is_admin isAdmin or .... check role admin

User model getIsAdminAttribute() https://www.youtube.com/watch?v=j97iBwTPlNE https://stackoverflow.com/questions/58889575/laravel-5-8-authuser-is-not-using-user-model public function getIsAdminAttribute() { return (bool) $this->admin; } Auth::user()->isAdmin or auth()->user()->isAdmin https://laracasts.com/discuss/channels/code-review/how-to-check-user-role-after-login namespace App; use App\Role; use Illuminate\Database\Eloquent\Model; class User extends Model { public function getIsAdminAttribute() { return $this->roles->pluck( 'name' )->contains( 'admin' ); } public function roles() { // you will need a role model // Role::class is equivalent to string 'App\Role' return $this->belongsToMany( Role::class, 'users_role' ); } } ```LoginController``` namespace App\Http\Controllers; use Illuminate\Http\Request; use Auth; use Input; use Validator; use Redirect; class LoginController extends Controller { // public function login_post( Request $request ) { $data = Input::except( array( '_token' ) ); // var_dump($data); $rule = array( 'email' => 'required|email', 'password' => 'required', ); $validator = Validator::make( $data, $rule ); if ($validator->fails()) { // should do something } else { // no need to populate $data again with the same values // $data = Input::except( array( '_token' ) ); if (Auth::attempt( $data )) { // here i want to check logged in user role $user = Auth::user(); if ($user->roles->pluck( 'name' )->contains( 'admin' )) { return Redirect::to( '/admin-dashboard' ); } return Redirect::to( '/dashboard' ); } } } } https://laravel.tw/docs/5.2/eloquent-serialization#appending-values-to-json ...

2020-10-14 · 1 min · 211 words · Me

Error Running: npm install vue-template-compiler --save-dev --production=false

 Error Additional dependencies must be installed. This will only take a moment. Running: npm install vue-template-compiler --save-dev --production=false https://qiita.com/ucan-lab/items/f5bcdfceecffb9def4c5 Use yarn, Not npm yarn add vue-template-compiler --dev --production=false yarn run dev

2020-10-13 · 1 min · 31 words · Me

[轉] Laravel Livewire vs Vue vs jQuery: Simple Example

 https://www.youtube.com/watch?v=o0HoP7WzRf0

2020-10-12 · 1 min · word · Me

php laravel UI Boostrap jetstream docker-compose

目錄裡面對應的檔案要先修改 === 設定修改 [docker-compose] docker-compose.yml ./backend 在執行docker-compose目錄下建立backend目錄,或者是移動位置 db-store 使用的是 volumes [mysql] infra/docker/mysql/Dockerfile mysql user password root 等等自行變更,變更後要記得修改 infra/docker/php/Dockerfile infra/docker/mysql/my.cnf collation_server = utf8mb4_unicode_ci [php] infra/docker/php/Dockerfile 如果上面mysql設定有變更,記得這裡也要跟著變更 ENV TZ=Asia/Taipei LANGUAGE=en_US:UTF-8 infra/docker/php/php.ini mbstring.language = zh-tw [nginx] infra/docker/nginx/Dockerfile ENV TZ=UTC+8 === 指令開始執行 docker-compose up -d docker-compose exec app composer create-project --prefer-dist laravel/laravel . == jetstream Livewire !Now No Use docker-compose exec app composer require laravel/jetstream docker-compose exec app php artisan jetstream:install livewire --teams docker-compose exec app php artisan migrate docker-compose exec web yarn install docker-compose exec web yarn dev == jetstream end ...

2020-10-12 · 1 min · 206 words · Me

blade @can @cannot

https://laravel.com/docs/8.x/authorization#via-blade-templates https://laravel.com/docs/8.x/authorization The gate methods for authorizing abilities (allows, denies, check, any, none, authorize, can, cannot) and the authorization Blade directives (@can, @cannot, @canany) can receive an array as the second argument. These array elements are passed as parameters to gate, and can be used for additional context when making authorization decisions

2020-10-12 · 1 min · 52 words · Me

php swoole

https://github.com/i-core/werther

2019-06-16 · 1 min · word · Me