定义控制器设置路由失败

定义控制器设置路由失败

http://img1.sycdn.imooc.com//climg/5e2412df09e30d3a19191054.jpg

http://img1.sycdn.imooc.com//climg/5e2412df0957146119191059.jpg

按照之前视频上的演示设置nolanguage并定义HelloController控制器可以成功,新建的two路由和HHController控制器却失败了

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

Route::get('/hello', 'HelloController@hello');
Route::get('/hello/{name}/{sex?}', 'HelloController@sayHello');

Route::get('/method', 'HelloController@methodName');
Route::post('/method', 'HelloController@methodName');
Route::patch('/method', 'HelloController@methodName');
Route::put('/method', 'HelloController@methodName');
Route::delete('/method', 'HelloController@methodName');
Route::options('/method', 'HelloController@methodName');

Route::match(['post', 'get'], '/match', 'HelloController@matchMethod');
Route::any('/matchall   ', 'HelloController@matchAll');

Route::resource('resource', 'ResourceController');
Route::get('/helloname/{name}', 'HelloController@helloName')->middleware('checkName');

//Route::get('/admin/test1', 'Admin\TestController@test1');
//Route::get('/admin/test2', 'Admin\TestController@test2');
//Route::get('/admin/test3', 'Admin\TestController@test3');

//Route::prefix('admin')->group(function() {
//    Route::get('test1', 'Admin\TestController@test1');
//    Route::get('test2', 'Admin\TestController@test2');
//    Route::get('test3', 'Admin\TestController@test3');
//});

Route::middleware('checkName')->group(function() {
    Route::get('test1/{name}', 'TestController@test1');
    Route::get('test2', 'TestController@test2');
    Route::get('test3', 'TestController@test3');
});

Route::get('testview/{name}', 'TestViewController@index');

Route::prefix('about')->group(function() {
    Route::get('job', 'TestViewController@job');
    Route::get('aboutus', 'TestViewController@aboutUs');
    Route::get('aboutgroup', 'TestViewController@aboutGroup');
});

Route::get('bladefunc', 'TestViewController@bladeFunc');
Route::get('testsql', 'TestSqlController@index');
Route::get('testsql/construct', 'TestSqlController@construct');

Route::get('testmodel', 'TestSqlController@testModel');
Route::get('testorm', 'TestSqlController@testOrm');
Route::get('testscope', 'TestSqlController@testScope');

Route::get('/Language',function () {//laravel 创建路由
    return 'PHP是世界上最好的语言';
});

//定义路由文件,让路由找到控制器 使用controllerName@functionName语法
//命名空间默认在 App\Http\Controllers目录下,可省略
Route::get('/nolanguage','HelloController@hello');
Route::get('/best','ProgramLanguageController@program');
Route::get('/one','ThetestController@test');
Route::get('/two','HHController@hh');
HelloController.php
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;

class HelloController extends Controller
{
    public function hello(){
        return 'Hello,World!';
    }
}//创建控制器
HHController.php
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;

class HHController extends Controller
{
    public function hh(){
        return 'HH';
    }
}


正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学你好,请问HHController类是否在Auth目录下,如果是则建议修改路由到Auth目录下,如下所示:

Route::get('/two','Auth\HHController@hh');

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

  • 断线纸鸢1 提问者 #1
    好啦,O(∩_∩)O谢谢老师!
    2020-01-19 17:03:14
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
PHP典型功能与Laravel5框架开发
  • 参与学习           人
  • 解答问题       721    个

掌握开发中必备技能解锁缓存、支付,邮件和短信发送等高端接口运用,直击工作重难点,通过开发简书项目熟练掌握Laravel5的开发技术。完成以上三个阶段的学习,成为满足企业需求的开发工程师。

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师