PHP code example of xiangyu2038 / wish

1. Go to this page and download the library: Download xiangyu2038/wish library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xiangyu2038 / wish example snippets


当前处理结果数据添加一个字段  test

 namespace App\Http;
 use XiangYu2038\Wish\XY;

  class TestController {
      public function index(Request $request){
          $test_model =   TestModel::first();///查询出一条数据
          $test_model =  XY::with($test_model) ->add('test') ->get();///$test_model 添加一个字段test

      }
  }
  



namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class TestModel extends Model
{
    //
    //指定表名
    protected $table = 'a_table';

    protected $guarded = [];
    public function getTest(){
    return 'test';
}



///属性转换
    //    protected $casts = [

}


$res = XY::with($model)->except('code','box_id','stock_id')->delete('stockDetail',true)->wish('boxDetail')->add('stock_sn')->add('box_sn')->delete('box',true)->except('box_id')->wish('box')->add('stock_sn')->wish('stockBox')->add('stock_sn')->get()->toArray();