繁体   English   中英

Laravel-在字符串上调用成员函数addEagerConstraints()

[英]Laravel - Call to a member function addEagerConstraints() on string

我正在对我的模型进行自定义功能,以检查用户是否属于外部api列表。

public function mailchimp()
    {
        $mailchimp = new Client(['base_uri' => 'https://us14.api.mailchimp.com/3.0/']);

        try
        {
            $checkEmail = $mailchimp->request('GET', 'lists/768ce70724/members/' . md5($this->email), [
                'headers' => [ 'Authorization' => 'apikey ' . config('globals.mailchimp_key') ]
            ]);
        }

        catch( \Exception $exception ) {
            //if ( $exception->getResponse()->getStatusCode() === 404) { return 'not a subscriber'; }

            return 'error'; // where the error occurs
        }

        $result = json_decode( $checkEmail->getBody() );

        //return    $result->status;
        return 'success';
    }

这就是我所说的方法:

$emails = $newsletter
                ->with('user')
                ->with('mailchimp')
                ->paginate(config('globals.results_per_page'));

return $emails;

错误: http//prntscr.com/dbm2ts

当您使用with() Laravel试图加载一个关系 因此, mailchimp()应该是此处的关系。

我无法转到控制器上的方法,但是我设法从视图中访问了它,效果很好!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM