首页 > 解决方案 > 当我运行项目时,它显示控制器没有在 laravel 中退出,但它在控制器文件夹中我该怎么办?

问题描述

SampleController.php、web.php、example.blade.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SampleController extends Controller
{

    public function index(){
        return view('example');
    }
    
}

网页.php

<?php

use Illuminate\Support\Facades\Route;

Route::get('/',function () {
  
  return view('welcome');
});

Route::get('/sample', 'SampleController@index');

例子.blade.php

<?php
echo 'hello world !!';
?>

标签: phplaravelcontroller

解决方案


我希望你正在使用 Laravel 8 并且它现在已经更新了,

use App\Http\Controllers\SampleController;

Route::get('/sample', [SampleController::class, 'index']);

请在此处查看更多详细信息, https://laravel.com/docs/8.x/routing


推荐阅读