清除所有缓存后,Laravel路由仍指向错误的控制器

时间:2019-06-17 05:10:55

标签: laravel controller laravel-5.8 php-7.1

我已经清除了Laravel应用程序中的所有缓存,但是当我访问URL时,例如:http://www.inwrite.com/turtle/blogs/post/lorem-ipsum;它返回Class App\Http\Controllers\Front\BlogController does not exist错误。我仔细检查了 routes.php 文件中的所有路由,特别是路由Route::get( '/blogs/post/{slug}', 'Front\BlogController@handle');和所有控制器(BlogController.php文件确实存在)。

routes.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('/', function () {
    return view('welcome');
});*/

// prevents unauthorized access
$c = [ \App\Http\Middleware\WebAuthMiddleware::class ];
/*TEST*/
Route::get(  '/test/test2',  'Front\TestController@handle');


/*ERROR PAGE*/
Route::get(  '/error',  'ErrorController@handle');

/*FRONT*/
Route::get(  '/',  'Front\FrontController@handle');

Route::get(  '/blogs',  'Front\BlogListController@handle');
Route::get(  '/blogs/{cat}',  'Front\BlogListController@setActiveCategory');
Route::get(  '/blogs/post/{slug}',  'Front\BlogController@handle');

Route::get(  '/page/{pg_slug}',  'Front\PageController@handle');

Route::get(  '/login',  'Front\LoginController@handle');
Route::post(  '/login',  'Front\LoginController@login');
Route::get(  '/logout',  'Front\LoginController@logout');

Route::post(  '/sign-up',  'Front\SignUpController@handle');

Route::get(  '/reset-password',  'Front\ResetPasswordController@handle');

Route::get(  '/dashboard',  'Front\DashboardController@handle');

Route::get(  '/create-new-order',  'Front\CreateNewOrderController@handle');

Route::post(  '/customer/edit',  'Front\CustomerEditController@handle')->middleware($c);

Route::post(  '/customer/update',  'Front\CustomerUpdateController@handle')->middleware($c);

/*ADMIN*/

Route::get(  'admin/login',    'Dashboard\DashboardLoginController@handle');
Route::post( 'admin/login',    'Dashboard\DashboardLoginPostController@handle');
Route::get(  'admin/logout',   'Dashboard\DashboardLogoutController@handle');

Route::get(  '/admin',  'Dashboard\DashboardController@handle')->middleware($c);

Route::get(  '/admin/orders',  'Dashboard\OrdersController@handle')->middleware($c);

Route::get(  '/admin/customers',  'Dashboard\CustomersController@handle')->middleware($c);
Route::post(  '/admin/customers/list',  'Dashboard\CustomersListController@handle')->middleware($c);
Route::post(  '/admin/customers/delete-many',  'Dashboard\CustomersDeleteManyController@handle')->middleware($c);

Route::get(  '/admin/administrators',  'Dashboard\AdministratorsController@handle')->middleware($c);
Route::post(  '/admin/administrators/list',  'Dashboard\AdministratorsListController@handle')->middleware($c);
Route::post(  '/admin/administrators/save',  'Dashboard\AdministratorsSaveController@handle')->middleware($c);
Route::post(  '/admin/administrators/edit',  'Dashboard\AdministratorsEditController@handle')->middleware($c);
Route::post(  '/admin/administrators/delete-many',  'Dashboard\AdministratorsDeleteManyController@handle')->middleware($c);

Route::get(  '/admin/services',  'Dashboard\ServicesController@handle')->middleware($c);
Route::post(  '/admin/services/list',  'Dashboard\ServicesListController@handle')->middleware($c);
Route::post(  '/admin/services/save',  'Dashboard\ServicesSaveController@handle')->middleware($c);
Route::post(  '/admin/services/edit',  'Dashboard\ServicesEditController@handle')->middleware($c);
Route::post(  '/admin/services/delete-many',  'Dashboard\ServicesDeleteManyController@handle')->middleware($c);

Route::get(  '/admin/operations/business-hours',  'Dashboard\OperationsBusinessHoursController@handle')->middleware($c);
Route::post(  '/admin/operations/business-hours/list',  'Dashboard\OperationsBusinessHoursListController@handle')->middleware($c);
Route::post(  '/admin/operations/business-hours/save',  'Dashboard\OperationsBusinessHoursSaveController@handle')->middleware($c);
Route::post(  '/admin/operations/business-hours/edit',  'Dashboard\OperationsBusinessHoursEditController@handle')->middleware($c);
Route::post(  '/admin/operations/business-hours/delete-many',  'Dashboard\OperationsBusinessHoursDeleteManyController@handle')->middleware($c);

Route::get(  '/admin/operations/dayoffs',  'Dashboard\OperationsDayoffsController@handle')->middleware($c);
Route::post(  '/admin/operations/dayoffs/list',  'Dashboard\OperationsDayoffsListController@handle')->middleware($c);
Route::post(  '/admin/operations/dayoffs/save',  'Dashboard\OperationsDayoffsSaveController@handle')->middleware($c);
Route::post(  '/admin/operations/dayoffs/edit',  'Dashboard\OperationsDayoffsEditController@handle')->middleware($c);
Route::post(  '/admin/operations/dayoffs/delete-many',  'Dashboard\OperationsDayoffsDeleteManyController@handle')->middleware($c);

Route::get(  '/admin/operations/holidays',  'Dashboard\OperationsHolidaysController@handle')->middleware($c);
Route::post(  '/admin/operations/holidays/list',  'Dashboard\OperationsHolidaysListController@handle')->middleware($c);
Route::post(  '/admin/operations/holidays/save',  'Dashboard\OperationsHolidaysSaveController@handle')->middleware($c);
Route::post(  '/admin/operations/holidays/edit',  'Dashboard\OperationsHolidaysEditController@handle')->middleware($c);
Route::post(  '/admin/operations/holidays/delete-many',  'Dashboard\OperationsHolidaysDeleteManyController@handle')->middleware($c);

Route::get(  '/admin/products',  'Dashboard\ProductsController@handle')->middleware($c);
Route::post(  '/admin/products/list',  'Dashboard\ProductsListController@handle')->middleware($c);
Route::post(  '/admin/products/save',  'Dashboard\ProductsSaveController@handle')->middleware($c);
Route::post(  '/admin/products/edit',  'Dashboard\ProductsEditController@handle')->middleware($c);
Route::post(  '/admin/products/delete-many',  'Dashboard\ProductsDeleteManyController@handle')->middleware($c);

Route::get(  '/admin/file-types',  'Dashboard\FileTypesController@handle')->middleware($c);
Route::post(  '/admin/file-types/list',  'Dashboard\FileTypesListController@handle')->middleware($c);
Route::post(  '/admin/file-types/save',  'Dashboard\FileTypesSaveController@handle')->middleware($c);
Route::post(  '/admin/file-types/edit',  'Dashboard\FileTypesEditController@handle')->middleware($c);
Route::post(  '/admin/file-types/delete-many',  'Dashboard\FileTypesDeleteManyController@handle')->middleware($c);

Route::get(  '/admin/messages',  'Dashboard\MessagesController@handle')->middleware($c);

Route::get(  '/admin/configurations',  'Dashboard\ConfigurationsController@handle')->middleware($c);
Route::post(  '/admin/configurations/list',  'Dashboard\ConfigurationsListController@handle')->middleware($c);
Route::post(  '/admin/configurations/save',  'Dashboard\ConfigurationsSaveController@handle')->middleware($c);
Route::post(  '/admin/configurations/edit',  'Dashboard\ConfigurationsEditController@handle')->middleware($c);
Route::post(  '/admin/configurations/delete-many',  'Dashboard\ConfigurationsDeleteManyController@handle')->middleware($c);

Route::get(  '/admin/cms/header',  'Dashboard\CmsNavbarsController@handle')->middleware($c);
Route::post(  '/admin/cms/header/list',  'Dashboard\CmsNavbarsListController@handle')->middleware($c);
Route::post(  '/admin/cms/header/save',  'Dashboard\CmsNavbarsSaveController@handle')->middleware($c);

Route::get(  '/admin/cms/footer',  'Dashboard\CmsFootersController@handle')->middleware($c);
Route::post(  '/admin/cms/footer/list',  'Dashboard\CmsFootersListController@handle')->middleware($c);
Route::post(  '/admin/cms/footer/save',  'Dashboard\CmsFootersSaveController@handle')->middleware($c);
Route::post(  '/admin/cms/footer/edit',  'Dashboard\CmsFootersEditController@handle')->middleware($c);
Route::post(  '/admin/cms/footer/delete-many',  'Dashboard\CmsFootersDeleteManyController@handle')->middleware($c);

Route::get(  '/admin/cms/sections',  'Dashboard\CmsSectionsController@handle')->middleware($c);
Route::post(  '/admin/cms/sections/list',  'Dashboard\CmsSectionsListController@handle')->middleware($c);
Route::post(  '/admin/cms/sections/save',  'Dashboard\CmsSectionsSaveController@handle')->middleware($c);
Route::post(  '/admin/cms/sections/edit',  'Dashboard\CmsSectionsEditController@handle')->middleware($c);
Route::post(  '/admin/cms/sections/delete-many',  'Dashboard\CmsSectionsDeleteManyController@handle')->middleware($c);
Route::post(  '/admin/cms/sections/sort',  'Dashboard\CmsSectionsSortController@handle')->middleware($c);

Route::get(  '/admin/cms/testimonials',  'Dashboard\CmsTestimonialsController@handle')->middleware($c);
Route::post(  '/admin/cms/testimonials/list',  'Dashboard\CmsTestimonialsListController@handle')->middleware($c);
Route::post(  '/admin/cms/testimonials/save',  'Dashboard\CmsTestimonialsSaveController@handle')->middleware($c);
Route::post(  '/admin/cms/testimonials/edit',  'Dashboard\CmsTestimonialsEditController@handle')->middleware($c);
Route::post(  '/admin/cms/testimonials/delete-many',  'Dashboard\CmsTestimonialsDeleteManyController@handle')->middleware($c);
Route::post(  '/admin/cms/testimonials/sort',  'Dashboard\CmsTestimonialsSortController@handle')->middleware($c);

Route::get(  '/admin/cms/faqs',  'Dashboard\CmsFaqsController@handle')->middleware($c);
Route::post(  '/admin/cms/faqs/list',  'Dashboard\CmsFaqsListController@handle')->middleware($c);
Route::post(  '/admin/cms/faqs/save',  'Dashboard\CmsFaqsSaveController@handle')->middleware($c);
Route::post(  '/admin/cms/faqs/edit',  'Dashboard\CmsFaqsEditController@handle')->middleware($c);
Route::post(  '/admin/cms/faqs/delete-many',  'Dashboard\CmsFaqsDeleteManyController@handle')->middleware($c);
Route::post(  '/admin/cms/faqs/sort',  'Dashboard\CmsFaqsSortController@handle')->middleware($c);

Route::get(  '/admin/cms/top-sliders',  'Dashboard\CmsTopSlidersController@handle')->middleware($c);
Route::post(  '/admin/cms/top-sliders/list',  'Dashboard\CmsTopSlidersListController@handle')->middleware($c);
Route::post(  '/admin/cms/top-sliders/save',  'Dashboard\CmsTopSlidersSaveController@handle')->middleware($c);
Route::post(  '/admin/cms/top-sliders/edit',  'Dashboard\CmsTopSlidersEditController@handle')->middleware($c);
Route::post(  '/admin/cms/top-sliders/delete-many',  'Dashboard\CmsTopSlidersDeleteManyController@handle')->middleware($c);
Route::post(  '/admin/cms/top-sliders/sort',  'Dashboard\CmsTopSlidersSortController@handle')->middleware($c);

Route::get(  '/admin/cms/external-pages',  'Dashboard\CmsExternalPagesController@handle')->middleware($c);
Route::post(  '/admin/cms/external-pages/list',  'Dashboard\CmsExternalPagesListController@handle')->middleware($c);
Route::post(  '/admin/cms/external-pages/save',  'Dashboard\CmsExternalPagesSaveController@handle')->middleware($c);
Route::post(  '/admin/cms/external-pages/edit',  'Dashboard\CmsExternalPagesEditController@handle')->middleware($c);
Route::post(  '/admin/cms/external-pages/delete-many',  'Dashboard\CmsExternalPagesDeleteManyController@handle')->middleware($c);
Route::post(  '/admin/cms/external-pages/get-category',  'Dashboard\CmsExternalPagesGetCategoryController@handle')->middleware($c);

Route::get(  '/admin/cms/categories',  'Dashboard\CmsCategoriesController@handle')->middleware($c);
Route::post(  '/admin/cms/categories/list',  'Dashboard\CmsCategoriesListController@handle')->middleware($c);
Route::post(  '/admin/cms/categories/save',  'Dashboard\CmsCategoriesSaveController@handle')->middleware($c);
Route::post(  '/admin/cms/categories/edit',  'Dashboard\CmsCategoriesEditController@handle')->middleware($c);
Route::post(  '/admin/cms/categories/delete-many',  'Dashboard\CmsCategoriesDeleteManyController@handle')->middleware($c);


/*Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');*/

BlogController.php

<?php

namespace App\Http\Controllers\Front;

use Illuminate\Http\Request;
use App\Http\Controllers\BaseController as BaseController;

class BlogController extends BaseController
{
    //
    public function handle(Request $request, $slug)
    {   
        $model = \App\Models\Posts::where('slug', $slug)->first();

        $blog_cats = \App\Models\BlogCategories::all();

        $title = 'Turtl-E | Blogs | '.$model->title;

        $viewData = [ 'title' => $title,
                      'model' => $model,
                      'blog_cats' => $blog_cats,
                      'blog_latest' => $this->getLatestPost(),
                      'header' => $this->getHeader(),
                      'footer' => $this->getFooter(),
                      'config' => $this->getConfig() ];
        return view($this->getFrontViewGroup().'blog_item', $viewData);
    }
}

BlogController.php 文件位于 app / Http / Controllers / Front 目录中。我做错了什么?

2 个答案:

答案 0 :(得分:0)

您应该运行composer dump-autoload命令来自动加载您的课程。

答案 1 :(得分:0)

由于在您的路线中使用 WILDCARD {} ,因此您的路线因 ORDER 而收到此错误。

让我们看看您的代码:

Route::get('/blogs/{cat}',  'Front\BlogListController@setActiveCategory');
Route::get('/blogs/post/{slug}',  'Front\BlogController@handle');

因此,当laravel处理您的代码时,它会找到

/ blog / 发布 / {slug}

并认为它是针对以下路由的请求: [由于 {cat} 是通配符,因此可以是任何通配符;帖子,猫什么]

Route::get('/blogs/{cat}',  'Front\BlogListController@setActiveCategory');

解决方案:更改路由的顺序 [首先是静态路由,然后是通配符路由]

Route::get('/blogs/post/{slug}',  'Front\BlogController@handle');
Route::get('/blogs/{cat}',  'Front\BlogListController@setActiveCategory');