【问题标题】:'Class 'App\Http\Controllers\Url' not found' -- Laravel 5 [closed]'找不到类'App\Http\Controllers\Url'--Laravel 5 [关闭]
【发布时间】:2015-06-04 10:57:31
【问题描述】:

我已经开始学习 Laravel 5。关注this tutorial。我收到此错误。 (Class 'App\Http\Controllers\Url' not found)。
我在这里附上了我的代码图片。



Whoops, looks like something went wrong.

1/1
FatalErrorException in UrlController.php line 22:
Class 'App\Http\Controllers\Url' not found
in UrlController.php line 22
at FatalErrorException->__construct() in compiled.php line 1838
at HandleExceptions->fatalExceptionFromError() in compiled.php line 1833
at HandleExceptions->handleShutdown() in compiled.php line 0
at UrlController->store() in compiled.php line 8504
at call_user_func_array:{C:\wamp\www\readit-later\vendor\compiled.php:8504}() in compiled.php line 8504
at Controller->callAction() in compiled.php line 8572
at ControllerDispatcher->call() in compiled.php line 8551
at ControllerDispatcher->Illuminate\Routing\{closure}() in compiled.php line 9190



帮帮我。

【问题讨论】:

  • 这是一个命名空间问题。将use Url 放在页面顶部或写$url = new \Url()。发生这种情况是因为您正在学习 laravel 4 教程,并且您使用的是 laravel 5,您需要在其中指定要使用的内容。
  • 你忘记创建 eloquent 模型了。

标签: php laravel-5 laravel-routing


【解决方案1】:

在控制器中添加

use URL;

【讨论】:

    【解决方案2】:

    您应该创建一个名称为 Url 的模型,或者在您的 app 文件夹中最适合您的名称,您也可以通过 artisan 命令生成一个 url 模型

    php artisan make:model Url
    

    或者您可以手动创建一个,例如

    <?php namespace App;
    
    use Illuminate\Database\Eloquent\Model;
    use Illuminate\Database\Query\Builder;
    
    protected $table = 'table_name' // in case your table name is different than plural of model name
    
    class Url extends Model
    {
    
    }
    

    然后在你的控制器中使用这个 Url 模型,例如

    use App\Url;
    

    然后你就可以使用了

    $url = new Url;
    $url->url = Request::get('url'); //make sure you have used use Illuminate\Http\Request; in starting of your controller 
    

    【讨论】:

      猜你喜欢
      • 2015-06-24
      • 2015-05-21
      • 2015-08-31
      • 2015-07-12
      • 2015-05-10
      • 2018-01-03
      • 1970-01-01
      • 2016-05-09
      • 2023-01-13
      相关资源
      最近更新 更多