我在我的Windows 7 64Bit Uwamp本地服务器中安装了Laravel 5.4最新版本。在包中找不到Laravel ServiceProvider类
我已经创建了以下在我的 “自定义” 包,我想在Laravel注册文件:
包/自定义/ timeshow/composer.json:
{
"name": "custom/timeshow",
"description": "Show Time in All Timezones",
"type": "composer-plugin",
"license": "GPL",
"authors": [
{
"name": "Test Author",
"email": "[email protected]"
}
],
"minimum-stability": "dev",
"require": {},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Custom\\Timeshow\\": "packages/custom/timeshow/src"
}
}
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php -r \"copy('.env.example', '.env');\"",
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
包\定制\ timeshow的\ src \ TimeshowServiceProvider.php
<?php
namespace Custom\Timeshow;
use Illuminate\Support\ServiceProvider;
class TimeshowServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
include __DIR__.'/routes.php';
$this->app->make('Custom\Timeshow\TimeshowController');
}
}
包\定制\ timeshow的\ src \ TimeshowController.php
<?php
namespace Custom\Timeshow;
use App\Http\Controllers\Controller;
use Carbon\Carbon;
class TimeshowController extends Controller
{
public function index($timezone)
{
echo Carbon::now($timezone)->toDateTimeString();
}
}
包\定制\ timeshow的\ src \ routes.php文件
<?php
Route::get('timeshow/{timezone}', 'Custom\Timeshow\[email protected]');
还包括我的服务提供商在配置/ app.php像这样:
Custom\Timeshow\TimeshowServiceProvider::class,
但即使在所有这一切,当我跑命令php artisan serve
,我得到下面的错误:
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Custom\Timeshow\TimeshowServiceProvider' not found
有人能说出什么是错在这一点,assit解决呢?
尝试运行'composer dump-autoload'命令。 – Webinion
只是...做到这一点... php工匠供应商:发布.. –
很多时候,即使使用'-o'参数,eveytime它说:“生成...成功”,但在相同的错误之后。 –