小编dra*_*ack的帖子

调用未定义的方法Illuminate\Database\Query\Builder :: associate()

参考:如何更新Laravel 4中现有的Eloquent关系?

$userinfo = \Userinfo::find($id);
\User::find($id)->userinfo()->associate($userinfo)->save();
Run Code Online (Sandbox Code Playgroud)

我收到错误: Call to undefined method Illuminate\Database\Query\Builder::associate()

这是整个方法:

public function saveUser($id)
{
    $user = \User::find($id);

    $userdata = \Input::all();

    $rules = array(
        'email' => 'required|email',
        'state' => 'size:2',
        'zip'   => 'size:5',
        'phone' => array('regex:/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/')
    );

    $validator = \Validator::make($userdata, $rules);

    if ($validator->passes())
    {
        if ($userdata['email'] !== $user->email)
        {
            $rules = array('email' => 'unique:users');
            $validator = \Validator::make($userdata, $rules);
            if ($validator->fails()) return Redirect::route('admin.user.edit', array('user' => $user))
                ->with('error', 'Specified email already exists.');
        }

        $user->email                = $userdata['email'];
        $user->firstname …
Run Code Online (Sandbox Code Playgroud)

php eloquent laravel-4

23
推荐指数
1
解决办法
6万
查看次数

访问stdClass对象中的属性

stdClass Object
(
[ModuleAccountInfo] => Array
    (
        [0] => stdClass Object
            (
                [ServerName] => EAST
                [HostingModule] => ActiveDirectory
                [ActiveDirectorySiteName] => EAST
                [AccountIdentity] => OU=ndla,OU=Hosting,DC=east,DC=domain,DC=local
                [Groups] => 2
                [Users] => 15
            )

        [1] => stdClass Object
            (
                [ServerName] => EAST.net
                [HostingModule] => hange
                [DiskQuota] => 375000
                [DiskQuotaAdditional] => 0
                [DateQuotaExceeded] => 0001-01-01T00:00:00
                [DiskSpace] => 58567
                [MailboxesDiskSpace] => 59973051
                [PublicFoldersDiskSpace] => 0
                [MessageArchivingDiskSpace] => 0
                [Contacts] => 8
                [Mailboxes] => 15
Run Code Online (Sandbox Code Playgroud)

如何访问ServerName属性?该对象保存在$ modules变量中.以上是$ modules的print_r.

php arrays object stdclass

10
推荐指数
1
解决办法
8587
查看次数

将命令的输出拆分为bash中的关联数组

输出是

/     ext4
/boot ext2
tank  zfs
Run Code Online (Sandbox Code Playgroud)

在每一行上,分隔符是一个空格.我需要一个关联数组,如:

"/" => "ext4", "/boot" => "ext2", "tank" => "zfs"
Run Code Online (Sandbox Code Playgroud)

怎么在bash中完成?

bash

10
推荐指数
1
解决办法
1805
查看次数

将此cURL转换为Guzzle

我试过阅读Guzzle文档,但我无法解决这个问题.

我想使用Guzzle代替cURL以下内容:

protected $url = 'https://secure.abcdef.com/cgi/xml_request_server.php';

    $xml =  "<ABCRequest>\n";
    $xml .=     "<Authentication>\n";
    $xml .=         "<ABLogin>$this->gwlogin</ABLogin>\n";
    $xml .=         "<ABKey>$this->gwkey</ABKey>\n";
    $xml .=     "</Authentication>\n";
    $xml .=     "<Request>\n";
    $xml .=            "<RequestType>SearchABC</RequestType>\n";
    $xml .=        "</Request>\n";
    $xml .= "</ABCRequest>\n";

    $header =  "POST $this->url HTTP/1.1\n";
    $header .= "Host: domain.com\n";
    $header .= "Content-Length: ".strlen($xml)."\n";
    $header .= "Content-Type: text/xml; charset=UTF8\n";
    $header .= "Connection: close; Keep-Alive\n\n";
    $header .= $xml;

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $this->url);
    curl_setopt($ch, CURLOPT_TIMEOUT, 120);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);

    $response = curl_exec($ch);
    curl_close($ch);
Run Code Online (Sandbox Code Playgroud)

我试过这个,但我还是新来的......:

$client …
Run Code Online (Sandbox Code Playgroud)

php xml xmlhttprequest guzzle

8
推荐指数
1
解决办法
6987
查看次数

PUT请求403禁止

使用laravel开发API.

在PUT请求上禁止403禁止.

适用于远程服务器但不适用于本地.将MAMP用于本地服务器.

这是我的虚拟主机,我没有看到任何关闭.

<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot "/Users/dg/Documents/Websites/domain.com/public_html/dev/public_html" ServerName domain.local ServerAlias www.domain.local <Directory /> Options Indexes FollowSymLinks AllowOverride All </Directory> ErrorLog "/Users/dg/Documents/Websites/domain.com/public_html/dev/error_log" CustomLog "/Users/dg/Documents/Websites/domain.com/public_html/dev/access_log" common </VirtualHost>

我已经在SO上查看了其他类似的问题,但还没有解决方案.

mamp apache2 laravel-4

5
推荐指数
1
解决办法
6949
查看次数

厨师覆盖同一食谱中另一个食谱的属性

我有一本包含 2 个食谱的食谱。

属性/default.rb default['vpn']['crt'] = 'nocrt'

默认配方具有创建通用 crt 文件的文件资源

file 'cert' do
    path "/etc/vpn/#{node.default['network']['hostname']}.crt"
    owner 'root'
    group 'root'
    mode '0644'
    content node.default['vpn']['crt']
end
Run Code Online (Sandbox Code Playgroud)

在第二个配方中client.rb,我包含默认配方,为该“客户端”加载加密数据包并覆盖该属性。但它不会被覆盖。

include_recipe 'my-cookbook'

vault = ChefVault::Item.load('auth', 'client')

node.override['vpn']['crt'] = vault['crt']

...
Run Code Online (Sandbox Code Playgroud)

文件内容 == 'nocrt'

根据Chef 的 Attribute Precedence,它应该覆盖vault['crt'].

更新:

Javier Cortejoso:您的答案在文件资源中使用时有效。

但请考虑以下示例:

属性/default.rb:

default['network']['hostname'] = 'generic-host-name'
Run Code Online (Sandbox Code Playgroud)

在 recipes/default.rb 中:

Chef::Log.info(node['network']['hostname'])
Chef::Log.info(node.default['network']['hostname'])
Chef::Log.info(node.override['network']['hostname'])
Run Code Online (Sandbox Code Playgroud)

在 recipes/client.rb 中:

node.override['network']['hostname'] = 'client-host-name'
include_recipe 'cookbook::default'
Run Code Online (Sandbox Code Playgroud)

因此,即使我先将执行顺序更改为 client.rb 配方,然后在覆盖后使用 default.rb,它仍然为我提供主机名“generic-host-name”:

==> default: [2015-03-04T17:30:43+00:00] INFO: generic-host-name
==> …
Run Code Online (Sandbox Code Playgroud)

chef-infra chef-recipe

5
推荐指数
1
解决办法
2508
查看次数

在 for 范围内使用 goroutine 运行 for range

我在循环中有一个 goroutine,我想同时为 ms.Entries 中的每个项目执行一个 goroutine,但它只针对循环中的最后一个项目运行。

我从一个更大的程序中抽象出了我的示例...... https://play.golang.org/p/whUMQ3pjq81

package main

import (
    "fmt"
    "sync"
)

type MyStruct struct {
    Entry   *Entry
    Entries *[]Entry
}

type Entry struct {
    ID   int
    Name string
}

type Fn struct {
    Res string
    Err error
}

func main() {
    e1 := Entry{ID: 1, Name: "First"}
    e2 := Entry{ID: 2, Name: "Second"}

    ms := &MyStruct{
        Entries: &[]Entry{e1, e2},
    }

    fmt.Printf("MS: %+v\n", ms)

    var wg sync.WaitGroup
    fnChan := make(chan *Fn)
    go func() {
        wg.Wait()
        close(fnChan)
    }()

    var …
Run Code Online (Sandbox Code Playgroud)

go

5
推荐指数
1
解决办法
2692
查看次数

PHP Soap身份验证标头

样品申请:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="https://ws.intermedia.net/Account/Management">

<soapenv:Header>
  <AuthentificationInfo>
     <login>[PLRAdminUserName]</login>
     <password>[PLRAdminPassword]</password>
     <accountID>[accountID]</accountID>
  </AuthentificationInfo>
</soapenv:Header>
<soapenv:Body>
  <GetAccount>
     <accountID>[accountID]</accountID>
  </GetAccount>
</soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)

WSDL:https://controlpanel.msoutlookonline.net/WebServices/Account/AccountService.asmx? WSDL

PHP:

    ini_set("soap.wsdl_cache_enabled", "0");

    $wsdl = "https://controlpanel.msoutlookonline.net/WebServices/Account/AccountService.asmx?WSDL";
    $ns = 'https://ws.intermedia.net/Account/Management';

    $client = new SoapClient($wsdl, array(
        "trace" => 1,
        "exceptions" => 0
    ));

    $login = 'xxxx';
    $password = 'xxxx';
    $partnerID = 1234;
    $accountID = 12345678;

    $headerBody = array('AuthentificationInfo'=>array(
        'login' => $login,
        'password' => $password,
        'accountID' => $partnerID
    ));
    $header = new SoapHeader($ns, 'AuthentificationInfo', $headerBody);
    $client->__setSoapHeaders($header);
    $client->__soapCall("echoVoid", array(null));

    $value = $client->GetAccount($accountID); …
Run Code Online (Sandbox Code Playgroud)

php api soap

1
推荐指数
1
解决办法
2万
查看次数