【发布时间】:2020-04-19 18:17:26
【问题描述】:
我使用Laravel Homestead作为我的开发环境,我开发了laravel应用程序,一切正常,我可以正确查看应用程序,但是当我使用相同的软件(php、mysql-server、redis)将它部署到VPS时,,,) 作为Laravel Homestead 但我得到FatalThrowableError : Class 'App\Http\Controllers\Admin\DatasourceCrudController' not found 我花了很多时间调查这个问题,但没有运气。
我发现类名是 DataSourceCrudController.php,在 DataSource 中带有大写 S,但错误是 DatasourceCrudController。
我试过了:
composer dump-autoload
php artisan cache:clear
php artisan config:clear
php artisan route:clear
但每次我得到类未找到异常。
本地和生产服务器上的代码相同,环境相同UBUNTU 18.04
请帮我解决这个问题。
谢谢,
更新 1:
web.php路线:
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', "PageController@index")->name("index");
Auth::routes();
Route::middleware('auth:web')->get('/home', 'HomeController@index')->name('home');
Route::get('/import', 'ImportController@import')->name('import');
Route::post('/parse', 'ImportController@parse')->name('parse');
Route::post('/process', 'ImportController@process')->name('process');
Route::post('/active-country/{activeCountry}', 'PageController@selectActiveCountry')->name("selectActiveCountry");
Route::prefix('graphs')->middleware('auth:web')->group(function(){
Route::get('/price-analysis', 'DyGraphController@create')->name("getPriceAnalysisForm");
Route::post('/price-analysis', 'DyGraphController@store')->name("postPriceAnalysisForm");
Route::get('/dygraph', 'DyGraphController@getGraphs')->name("dygraph");
Route::get('/trends-analysis', 'TrendsAnalysisController@commoditiesTrendsPage')->name('trendAnalysisPage');
});
Route::prefix('analysis')->middleware('auth:web')->group(function (){
Route::get('/your-analysis', 'CustomAnalysisController@create')->name('yourAnalysisPage');
});
类文件:DataSourceCrudController.php
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\Operations\UploadOperation;
use App\Http\Requests\DatasourceRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
/**
* Class DatasourceCrudController
* @package App\Http\Controllers\Admin
* @property-read CrudPanel $crud
*/
class DataSourceCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
use UploadOperation;
public function setup()
{
$this->crud->setModel('App\DataSource');
$this->crud->setRoute(config('backpack.base.route_prefix').'/datasource');
$this->crud->setEntityNameStrings('data source', 'data sources');
$this->crud->enableExportButtons();
}
protected function setupListOperation()
{
$this->crud->addColumn([
'name' => 'row_number', 'type' => 'row_number', 'label' => '#', 'orderable' => false
])->makeFirstColumn();
$this->crud->addColumn([
'name' => 'file_name',
'type' => 'text',
'label' => 'File Name'
]);
$this->crud->addColumn([
'label' => 'Country',
'type' => 'text',
'name' => 'country_name'
]);
$this->crud->addColumn([
'name' => "rows",
'label' => "Rows",
'type' => "number"
]);
$this->crud->addColumn([
'name' => 'imported',
'key' => 'check',
'label' => 'Imported',
'type' => 'check',
]);
$this->crud->addColumn([
'name' => 'created_at',
'label' => 'Date',
'type' => 'datetime'
]);
}
protected function setupUploadOperation()
{
$this->crud->setValidation(DatasourceRequest::class);
/*
* Get Active Countries Ajax /api/active-countries
* */
/*$this->crud->addField([
'label' => 'Active Country',
'type' => 'select2_from_ajax',
'name' => 'active_country_id',
'entity' => 'activeCountry',
'attribute' => 'name',
'model' => 'App\Country',
'data_source' => url('api/active-countries'),
'placeholder' => 'Select a Country',
'minimum_input_length' => 3,
]);*/
$this->crud->addField(
[ // Select2
'label' => 'Country',
'type' => 'select2',
'name' => 'active_country_id', // to display active countries
'entity' => 'activeCountry',
'attribute' => 'name',
'model' => 'App\ActiveCountry',
'options' => (function ($query) {
return $query->orderBy('id', 'DESC')->get();
}),
]
);
$this->crud->addField(
[
'label' => "Data Source File",
'name' => "import_file",
'type' => 'upload',
'upload' => true,
]);
$this->crud->addField(
[
'name' => 'header',
'label' => 'Excel file contains header',
'type' => 'checkbox',
]);
}
}
更新 2:
我正在使用背包管理面板,这个控制器用于构建一个 crud 操作和custom.php 中的管理路由:
<?php
// --------------------------
// Custom Backpack Routes
// --------------------------
// This route file is loaded automatically by Backpack\Base.
// Routes you generate using Backpack\Generators will be placed here.
Route::group([
'prefix' => config('backpack.base.route_prefix', 'admin'),
'middleware' => ['web', config('backpack.base.middleware_key', 'admin')],
'namespace' => 'App\Http\Controllers\Admin',
], function () { // custom admin routes
Route::crud('country', 'CountryCrudController');
Route::crud('currency', 'CurrencyCrudController');
Route::crud('commodity', 'CommodityCrudController');
Route::crud('market', 'MarketCrudController');
Route::crud('period', 'PeriodCrudController');
Route::crud('measure_unit', 'MeasureUnitCrudController');
Route::crud('datasource', 'DataSourceCrudController');
Route::crud('commodity_rate', 'CommodityRateCrudController');
Route::crud('activecountry', 'ActiveCountryCrudController');
Route::crud('availability', 'AvailabilityCrudController');
Route::crud('pricetype', 'PricetypeCrudController');
}); // this should be the absolute last line of this file
【问题讨论】:
-
你能告诉我们你的
web.php文件和你的控制器文件吗? -
我在更新 1 中添加了文件
标签: php laravel ubuntu homestead