【问题标题】:Laravel get Internal Server Error how can solve it?Laravel 得到 Internal Server Error 怎么解决?
【发布时间】:2020-10-29 20:31:42
【问题描述】:

Laravel 得到 Internal Server Error 怎么解决?

这是我的 web.php 代码

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

Route::get('/fleet', 'FleetController@index')->name('fleet');
Route::get('/offers', 'OffersController@index')->name('Offers');

当我链接到车队页面时,我会收到内部服务器错误。

我的文件夹是

resources
|-view
   |--index.blade.php
   |--fleet.blade.php
   |--offers.blade.php

这是 index.blade.php 代码

<li class="nav-item"><a class="nav-link" href="{{ route('fleet') }}">Fleet</a></li>
<li class="nav-item"><a class="nav-link" href="{{ route('offers') }}">Offers</a></li>

如何解决?

我的 apache 设置是

DocumentRoot "D:\xampp\htdocs\laravel\wine\public"

我的 FleetController 代码

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

舰队模型

class Fleet extends Model
{
    //
}

还是报错

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at postmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

Apache/2.4.43 (Win64) OpenSSL/1.1.1g PHP/7.4.6 Server at localhost Port 80

【问题讨论】:

  • 请尝试运行 artisan 命令php artisan serve 并使用服务链接而不是本地主机,看看错误是否消失

标签: laravel


【解决方案1】:

请进一步了解laravel Route

最基本的 Laravel 路由只接受一个URI 和一个Closure

现在看看你的代码

Route::get('/fleet')->name('fleet');
Route::get('/offers')->name('offers');

你只给URI,但你不给关闭

基本路线:

Route::get('/fleet',function(){
    // what do you want to do with that URI
})->name('fleet');

您还可以为控制器操作指定路由名称:

Route::get('user/profile', 'UserProfileController@show')->name('profile');

你需要为上面的路由创建一个文件UserProfileController

【讨论】:

    【解决方案2】:

    这些路由没有采取任何行动。你必须设置一个控制器。

    示例: Route::get('/fleet', 'MyController@my_method)-&gt;name('fleet');

    【讨论】:

      【解决方案3】:

      如果你想跳过控制器的介绍,你可以像当前家/路由一样简单。

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

      【讨论】:

        猜你喜欢
        • 2020-03-08
        • 2020-06-18
        • 1970-01-01
        • 2015-08-16
        • 1970-01-01
        • 1970-01-01
        • 2021-06-02
        • 2020-09-11
        • 2020-03-17
        相关资源
        最近更新 更多