当前位置: 首页>>代码示例>>PHP>>正文


PHP Datasource::make方法代码示例

本文整理汇总了PHP中Datasource::make方法的典型用法代码示例。如果您正苦于以下问题:PHP Datasource::make方法的具体用法?PHP Datasource::make怎么用?PHP Datasource::make使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Datasource的用法示例。


在下文中一共展示了Datasource::make方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testExistingChildren

 public function testExistingChildren()
 {
     // --- test load
     $this->createModels(CustomerDetail::class, []);
     $this->createModels(Customer::class, [['name' => 'Frank', 'surname' => 'Sinatra']]);
     $details = new CustomerDetail();
     $source = Datasource::make(new CustomerDetail());
     $source['id'] = 1;
     $source['biography'] = 'A nice life!';
     $source['accepts_cookies'] = 0;
     $source['customer_id'] = 1;
     $details->id = 1;
     $details->biography = 'A nice life!';
     $details->accepts_cookies = 0;
     $details->customer_id = 1;
     $source->save();
     assertTrue(isset($source['customer']));
     assertInstanceOf(Customer::class, $source['customer']);
     assertModelArrayEqual(Customer::all()->toArray(), [$source['customer']->toArray()]);
     // compare with how eloquent behaves:
     $this->createModels(CustomerDetail::class, []);
     $details->save();
     assertFalse(isset($details->customer));
     // always false!
     assertInstanceOf(Customer::class, $details->customer);
 }
开发者ID:tacone,项目名称:datasource,代码行数:26,代码来源:BelongsToOneTest.php

示例2: testCreateChildren

 public function testCreateChildren()
 {
     $this->createModels(Customer::class, []);
     $this->createModels(Order::class, []);
     // test creation
     $customer = new Customer();
     $source = Datasource::make($customer);
     $source['name'] = 'Frank';
     $source['surname'] = 'Sinatra';
     $source['orders.0.code'] = 'a1';
     $source['orders.0.shipping'] = 'home';
     $source['orders.1.code'] = 'b1';
     $source['orders.1.shipping'] = 'office';
     $source->save();
     assertModelArrayEqual([['name' => 'Frank', 'surname' => 'Sinatra']], Customer::all()->toArray());
     assertModelArrayEqual([['code' => 'a1', 'shipping' => 'home', 'customer_id' => 1], ['code' => 'b1', 'shipping' => 'office', 'customer_id' => 1]], Order::all()->toArray());
 }
开发者ID:tacone,项目名称:datasource,代码行数:17,代码来源:HasManyTest.php

示例3: testCreateChildren

 public function testCreateChildren()
 {
     $this->createModels(Order::class, []);
     $this->createModels(Book::class, []);
     // test creation
     $order = new Order();
     $source = Datasource::make($order);
     $source['code'] = 'a1';
     $source['shipping'] = 'home';
     $source['customer_id'] = '1';
     $source['books.0.title'] = 'Happiness';
     $source['books.1.title'] = 'Delight';
     $source->save();
     assertModelArrayEqual([['code' => 'a1', 'shipping' => 'home', 'customer_id' => 1]], Order::all()->toArray());
     assertModelArrayEqual([['title' => 'Happiness'], ['title' => 'Delight']], Book::all()->toArray());
     // repeat
     $source->save();
     assertModelArrayEqual([['code' => 'a1', 'shipping' => 'home', 'customer_id' => 1]], Order::all()->toArray());
     assertModelArrayEqual([['title' => 'Happiness'], ['title' => 'Delight']], Book::all()->toArray());
 }
开发者ID:tacone,项目名称:datasource,代码行数:20,代码来源:BelongsToManyTest.php


注:本文中的Datasource::make方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。