【问题标题】:I am unable to view created page using routing and controller in Laravel我无法在 Laravel 中使用路由和控制器查看创建的页面
【发布时间】:2021-04-03 09:57:37
【问题描述】:

我是新 Laravel,这是我的第一个项目,我得到的这个项目已经有一些页面,我必须添加一个管理员登录页面,所以我在资源文件夹中创建了 adminlogin.blade.php 文件,并制作控制器使用命令

php artisan make:controller AdminController

然后在AdminController中,我创建了一个函数

public function viewAdminLogin() {
    return "Hello From admin login controller";//not working
    return view('adminlogin');//this one also not working, i have tried both return statement one by one.
}

然后在 routes/web.php 中,我添加了这段代码

    <?php
    use Illuminate\Support\Facades\Route;
    /*
    |--------------------------------------------------------------------------
    | 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('/pricing', 'CalculatorController@index');

    Route::post('/quote', 'CalculatorController@quote');

    Route::get('/', 'Controller@index');

    // pages view
    Route::get('/howitworks', 'Controller@howitworks');

    Route::get('/US-Domestic-Shipping-Services', 'Controller@USDomesticShippingServices');

    Route::get('/International-Shipping-Services', 'Controller@InternationalShippingServices');

    Route::get('/Ship-Packages', 'Controller@ShipPackages');

    Route::get('/Ship-Envelopes', 'Controller@ShipEnvelopes');

    Route::get('/Student-Shipping', 'Controller@StudentShipping');

    Route::get('/about', 'Controller@About');

    Route::get('/FAQs', 'Controller@FAQs');

    Route::get('/Prohibited-Items', 'Controller@ProhibitedItems');

    Route::get('/Track-Shipment', 'Controller@TrackShipment');

    Route::get('/contact', 'Controller@Contact']);

    Route::get('/adminlogin', 'AdminController@viewAdminLogin');

我在导入这个项目后也运行了这一系列命令:

composer install
php artisan key:generate
php artisan migrate
php artisan db:seed
php artisan serve

运行http://127.0.0.1:8000/adminlogin后返回404页面,请帮忙谢谢阅读。

【问题讨论】:

  • php artisan route:clear 之后尝试,如果仍然无法正常工作,那么您使用相同的方法具有相同的 URI 前缀。使用php artisan route:list 的输出更新您的问题
  • @EsTeAa 不起作用
  • @EsTeAa 我通过列表命令 GET|HEAD | 得到了这个管理员登录 | | App\Http\Controllers\AdminController@viewAdminLogin |网络
  • 你能访问/FAQs , /about 吗?
  • 是的,其他页面正在运行

标签: php laravel


【解决方案1】:

运行以下清除命令:

//---Regenerates the list of all classes that need to be included in the project
composer dump-autoload;
//---Remove Routes Cache
php artisan route:clear;
//---Flush the application cache
php artisan cache:clear;
//---Remove the configuration cache file
php artisan config:cache;
php artisan config:clear;

然后重启你的服务器

php artisan serve

【讨论】:

  • 我认为你的清除命令有效,我在清除后重新启动了服务命令然后它有效
  • 删除controller.php和web.php代码,只保留清晰的命令并添加注释以重新启动服务器或服务命令。然后我会接受你的回答,这对其他人也有帮助。
  • 好的,我已经删除了您要求的代码。
  • 这个问题只与route cache有关,与作曲家、应用缓存、配置缓存无关
  • 是的,我得到了答案,但最好也删除这些缓存。
【解决方案2】:

如果你的路由已经被缓存,那么你需要清除缓存数据:

php artisan route:clear

如果你想缓存它,那么只需运行:

php artisan route:cache

这是关于路由缓存的official documentation

【讨论】:

    猜你喜欢
    • 2018-11-19
    • 2020-12-08
    • 1970-01-01
    • 1970-01-01
    • 2017-02-27
    • 2012-11-05
    • 2023-03-27
    • 2017-03-05
    • 2020-02-29
    相关资源
    最近更新 更多