donlih2986 2015-07-29 18:30
浏览 30
已采纳

Laravel从4.2迁移到5.1错误

I'm having a tough time migrating the Laravel 4.2 files to Laravel 5.1. I know it works with a lot of namespacing. So probably most of my errors would be because of the namespace issues. But I'm a bit new to namespace things. So I've some problems. I hope this would also benefit to some other users as well.

Composer.json file :

   "classmap": [
        "database",
        "app/Http/Controllers",
        "app/Models"
    ],
  1. According to the Laravel 5.1 updgrade documentation, I've creates a App\Models structure for the Models.

I'm getting this error related to Models. Where Backers.php and User are the models. What namespace should I provide to avoid this?

FatalErrorException in Backers.php line 16: Class 'User' not found

  1. I've used User::find($id) in some Views and Controllers. Instead of always calling \App\User::find($id), is there any other way I could approach this problem?

  2. displayLesson is a route name and sometimes I'm getting an error like

App\Http\Controllers\displayLesson not found.

How can I approach these problems?

  • 写回答

1条回答 默认 最新

  • doubeizhong5178 2015-07-29 19:11
    关注

    I don't understand ur exact problem but u can write "use .. as ..." at the top of the class after namespace the class name you use alot to avoid writing App\User

    namespace App\http\superImportantController Use App\User as User;

    Or not a very good practice but time consuming is to add your model into facades in app.php

    However , I guess the best practice is to use proper namespacing to be compliant with psr-7

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)