我在我的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它說:「生成...成功」,但在相同的錯誤之後。 –