使用pluck获取电子邮件的价值-PHP Laravel

时间:2018-08-29 05:39:06

标签: php laravel

$response['inserted_data'] =
array:3 [
    0 => array:16 [
        "name" => "Khv"
        "emails" => array:1 [
            0 => array:1 [
                "email" => "demo@yahoo.com"
            ]
        ]
    ]
    1 => array:18 [
        "name" => "Aesha"
        "emails" => array:1 [
            0 => array:1 [
                "email" => "test2@gmail.com"
            ]
        ]
    ]

如何使用demo@yahoo.com获取电子邮件值test2@gmail.compluck - php laravel,然后从该电子邮件中获取数据库中的_id并更新该记录。

2 个答案:

答案 0 :(得分:1)

尝试以下代码: 假设您的数据看起来像下面的数组,即$ arrays。



    resource "azurerm_resource_group" "main" {
      name     = "test-resources"
      location = "West US 2"
    }

    resource "azurerm_virtual_network" "main" {
      name                = "test-network"
      address_space       = ["10.0.0.0/16"]
      location            = "${azurerm_resource_group.main.location}"
      resource_group_name = "${azurerm_resource_group.main.name}"
    }

    resource "azurerm_subnet" "internal" {
      name                 = "internal"
      resource_group_name  = "${azurerm_resource_group.main.name}"
      virtual_network_name = "${azurerm_virtual_network.main.name}"
      address_prefix       = "10.0.2.0/24"
    }

    resource "azurerm_public_ip" "test" {
      name                         = "test-public-ip"
      location                     = "${azurerm_resource_group.main.location}"
      resource_group_name          = "${azurerm_resource_group.main.name}"
      public_ip_address_allocation = "dynamic"

      tags {
        environment = "production"
      }
    }

    resource "azurerm_network_interface" "main" {
      name                = "test-nic"
      location            = "${azurerm_resource_group.main.location}"
      resource_group_name = "${azurerm_resource_group.main.name}"

      ip_configuration {
        name                          = "testconfiguration1"
        subnet_id                     = "${azurerm_subnet.internal.id}"
        private_ip_address_allocation = "dynamic"
        public_ip_address_id = "${azurerm_public_ip.test.id}"
      }
    }

    resource "azurerm_virtual_machine" "main" {
      name                  = "test-vm"
      location              = "${azurerm_resource_group.main.location}"
      resource_group_name   = "${azurerm_resource_group.main.name}"
      network_interface_ids = ["${azurerm_network_interface.main.id}"]
      vm_size               = "Standard_DS1_v2"

      # Uncomment this line to delete the OS disk automatically when deleting the VM
      # delete_os_disk_on_termination = true


      # Uncomment this line to delete the data disks automatically when deleting the VM
      # delete_data_disks_on_termination = true

      storage_image_reference {
        publisher = "Canonical"
        offer     = "UbuntuServer"
        sku       = "16.04-LTS"
        version   = "latest"
      }

      storage_os_disk {
        name              = "myosdisk1"
        caching           = "ReadWrite"
        create_option     = "FromImage"
        managed_disk_type = "Standard_LRS"
      }

      os_profile {
        computer_name  = "hostname"
        admin_username = "testadmin"
        admin_password = "Password1234!"
      }

      os_profile_linux_config {
        disable_password_authentication = false
      }

      tags {
          environment = "production"
      }
    }

    output "vm-ip" {
        value = "${azurerm_public_ip.test.ip_address}"
    }

注意:您不能在数组上使用pluck,只能在集合上使用。

答案 1 :(得分:0)

您可以通过如下方式从摘心中获得价值。

User::all()->pluck('email');