从上下文 'Illuminate\Support\Facades\Facade 调用私有方法 App\Helper\ProfilePrivacy::get_by_contact()
Posted
技术标签:
【中文标题】从上下文 \'Illuminate\\Support\\Facades\\Facade 调用私有方法 App\\Helper\\ProfilePrivacy::get_by_contact()【英文标题】:Call to private method App\Helper\ProfilePrivacy::get_by_contact() from context 'Illuminate\Support\Facades\Facade从上下文 'Illuminate\Support\Facades\Facade 调用私有方法 App\Helper\ProfilePrivacy::get_by_contact() 【发布时间】:2017-10-06 08:55:20 【问题描述】:门面代码:
<?php
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class ProfilePrivacy extends Facade
protected static function getFacadeAccessor()
return 'profileprivacy';
?>
帮助代码
<?php
namespace App\Helper;
// Server file
use App\Http\Models\Privacy as PrivacyModel;
class ProfilePrivacy
private $_model;
public function __construct()
$this->_model = new PrivacyModel();
private function get_by_id($id)
$result=$this->_model->get_by_id($id);
private function get_by_contact($id)
$result=$this->_model->get_by_contact($id);
private function user_profileimage_privacy($id)
$result=$this->_model->user_profileimage_privacy($id);
?>
提供者
<?php
namespace App\Providers;
use App\Helper\ProfilePrivacy;
use Queue;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Log;
class ProfilePrivacyServiceProvider extends ServiceProvider
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
Queue::failing(function ($event)
);
/**
* Register the application services.
*
* @return void
*/
public function register()
$this->app->bind('profileprivacy', function ()
return new ProfilePrivacy;
);
app.php
$app->register(App\Providers\ProfilePrivacyServiceProvider::class);
网络路由
$app->get('democlass', function()
$imagepath = \App\Facades\ProfilePrivacy::get_by_contact('test');
print_r($imagepath);
);
我收到错误 Fatal error: Call to private method App\Helper\ProfilePrivacy::get_by_contact() from context 'Illuminate\Support\Facades\Facade' in C:\xampp\htdocs\voip_api\api\vendor\illuminate \support\Facades\Facade.php 在第 221 行 我在哪里做错了,请概述代码
【问题讨论】:
get_by_contact($id) 在您的 ProfilePrivacy 助手中是私有的。就公开吧? PHP: Class extends problem "Call to private method ... from context ..."的可能重复 【参考方案1】:改为从私有功能改为公共功能
【讨论】:
以上是关于从上下文 'Illuminate\Support\Facades\Facade 调用私有方法 App\Helper\ProfilePrivacy::get_by_contact()的主要内容,如果未能解决你的问题,请参考以下文章
将 Illuminate\database 默认返回类型的 Illuminate\Support\Collection 更改为数组版本 5.8
找不到错误类“Illuminate\Support\Facades\RateLimiter”
方法 Illuminate\Support\Collection::find 不存在
间接修改 Illuminate\Support\Collection 的重载元素无效
类 Illuminate\Support\Facades\RateLimiter 未找到
Laravel - 方法 Illuminate\\Support\\Collection::makeHidden 不存在