【问题标题】:Laravel 5.4 - Adldap - Call to undefined method Adldap\Adldap::search()Laravel 5.4 - Adldap - 调用未定义的方法 Adldap\Adldap::search()
【发布时间】:2017-02-06 16:03:30
【问题描述】:

我在安装 Laravel 和使用 Adldap 时遇到问题... 我收到的错误消息:

FatalThrowableError in UserCreationController.php line 100:
Class 'App\Http\Controllers\Adldap' not found

我已经根据文档安装/部署了 Adldap,当我从其他位置调用它时它正在工作。

工作的东西

Route::get('ldap', function() {
    $results = Adldap::search()->where('ou', 'ends_with', ' Users')
                               ->orWhere('ou','not_contains', 'Production')  
                               ->sortBy('ou', 'asc')
                               ->get();


    foreach ($results as $result) {
        dump ($result->ou);
    }

页面正确显示转储。一切都很好。

工作的东西(产生上面列出的错误代码)。 路由调用控制器...

路线:

Route::get('newuser', 'UserCreationController@GetUserOrganizationalUnits'); 

控制器:

public function GetUserOrganizationalUnits()
{
    $results = Adldap::search()->where('ou', 'ends_with', ' Users')
                               ->orWhere('ou','not_contains', 'Production')  
                               ->sortBy('ou', 'asc')
                               ->get();
    return view('newuserform',compact('results'));
}   

为什么它直接在 web php 中使用路由而不是从被调用的控制器中工作?

我已经尝试明确添加以下内容...

use Adldap\Contracts\AdldapInterface;

门面被声明,它在网络路由中工作,甚至不需要调用这个......

你能帮忙吗?

谢谢。

【问题讨论】:

    标签: laravel adldap


    【解决方案1】:

    我想你忘了包含 Facade

    在你的 UserCreationController.php 中添加:use Adldap;

    【讨论】:

    • 确实,我做到了。好。起初我没有,但我有其他错误让我评论出来......我认为我不需要这样做,因为它在 Facades 中并从 web 路由文件工作...... 谢谢 - 问题已解决。 :)
    【解决方案2】:

    您还需要在您的 UserCreationController 中使用它才能使用“使用 Adldap\Contracts\AdldapInterface;”方法:

    protected $adldap;
    
    public function __construct(AdldapInterface $adldap)
    {
        $this->adldap = $adldap;
    }
    

    或者在你的 config/app.php 中实现外观:

    'Adldap' => Adldap\Laravel\Facades\Adldap::class
    

    【讨论】:

      猜你喜欢
      • 2017-11-11
      • 1970-01-01
      • 1970-01-01
      • 2022-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多