本文整理汇总了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);
}
示例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());
}
示例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());
}