當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。