本文整理匯總了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());
}