Маршрут Laravel по-прежнему указывает на неправильный контроллер после очистки всех кэшей - PullRequest
0 голосов
/ 17 июня 2019

Я уже очистил все кеши в моем приложении Laravel, но когда я получаю доступ к URL, как, например, http://www.inwrite.com/turtle/blogs/post/lorem-ipsum;, возвращается Class App\Http\Controllers\Front\BlogController does not exist ошибка.Я дважды проверил все маршруты в моем файле rout.php , в частности маршрут Route::get( '/blogs/post/{slug}', 'Front\BlogController@handle'); и все контроллеры (файл BlogController.php действительно существует).

rout.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 голосов
/ 17 июня 2019

Вы получаете эту ошибку из-за ORDER ваших маршрутов, поскольку вы используете WILDCARD т.е. {} в ваших маршрутах.

Давайте посмотрим на вас код:

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

Итак, когда laravel обрабатывает ваш код, он находит

/ блог / сообщение / {пробкового}

и считает его запросом следующего маршрута: [Так как {cat} является подстановочным знаком, так что это может быть что угодно; почта, кошка что-нибудь]

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

Решение: измените порядок ваших маршрутов [сначала статические маршруты, затем маршруты с подстановочными знаками]

Route::get('/blogs/post/{slug}',  'Front\BlogController@handle');
Route::get('/blogs/{cat}',  'Front\BlogListController@setActiveCategory');
0 голосов
/ 17 июня 2019

вы должны запустить composer dump-autoload команду для автозагрузки ваших классов.

...