AliasLoader 在 Laravel 中找不到 Facade
Facade not found by AliasLoader in Laravel
我在 'aliases'
下的 laravel 项目中为我的 'config/app.php' 添加了自定义外观
'GeoLocation' => '\App\Facades\GeoLocation',
自定义class的文件夹在'app/Facades/GeoLocation.php'
,服务提供商在'app/Providers/GeoLocationServiceProvider.php'
如何在 app.php 中声明正确的别名才能正确加载 Facade?错误信息是:
ErrorException in AliasLoader.php line 63:
Class 'Facades\GeoLocation' not found
这是我的门面:
<?php namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class GeoLocation extends Facade {
protected static function getFacadeAccessor() { return 'geolocation'; }
}
会不会是我服务商的return值不对?
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class GeoLocationServiceProvider extends ServiceProvider {
public function register() {
\App::bind('geolocation', function()
{
return new GeoLocation;
});
}
}
为了测试,我创建了另一个名为自定义函数的服务提供者:
<?php namespace App\Helpers;
class CustomFunction {
//Generate random float between -1 and 1
function f_rand($min = 0, $max = 1, $mul = 1000000) {
if ($min>$max) return false;
return mt_rand($min*$mul, $max*$mul) / $mul;
}
function test() {
echo "OK";
}
}
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class CustomFunctionServiceProvider extends ServiceProvider {
public function register() {
\App::bind('customfunctions', function()
{
return new CustomFunction;
});
}
}
最简单的方法是将文件 app/Facades/GeoLocation.php' 的命名空间更改为 App\Facades
;
然后将别名注册更新为
'GeoLocation' => 'App\Facades\GeoLocation',
我在 'aliases'
下的 laravel 项目中为我的 'config/app.php' 添加了自定义外观'GeoLocation' => '\App\Facades\GeoLocation',
自定义class的文件夹在'app/Facades/GeoLocation.php'
,服务提供商在'app/Providers/GeoLocationServiceProvider.php'
如何在 app.php 中声明正确的别名才能正确加载 Facade?错误信息是:
ErrorException in AliasLoader.php line 63:
Class 'Facades\GeoLocation' not found
这是我的门面:
<?php namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class GeoLocation extends Facade {
protected static function getFacadeAccessor() { return 'geolocation'; }
}
会不会是我服务商的return值不对?
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class GeoLocationServiceProvider extends ServiceProvider {
public function register() {
\App::bind('geolocation', function()
{
return new GeoLocation;
});
}
}
为了测试,我创建了另一个名为自定义函数的服务提供者:
<?php namespace App\Helpers;
class CustomFunction {
//Generate random float between -1 and 1
function f_rand($min = 0, $max = 1, $mul = 1000000) {
if ($min>$max) return false;
return mt_rand($min*$mul, $max*$mul) / $mul;
}
function test() {
echo "OK";
}
}
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class CustomFunctionServiceProvider extends ServiceProvider {
public function register() {
\App::bind('customfunctions', function()
{
return new CustomFunction;
});
}
}
最简单的方法是将文件 app/Facades/GeoLocation.php' 的命名空间更改为 App\Facades
;
然后将别名注册更新为
'GeoLocation' => 'App\Facades\GeoLocation',