doufeng2877 2014-11-30 05:42
浏览 1631
已采纳

Laravel从数据库Eloquent ORM中获取错误

I am developing a Simple CRUD Application, I want to fetch my forms details from my forms table.

my controller look like below,

public function manage_forms()
{
    $form_data=Form::all();
    return View::make('manage_forms')->with('form_array',$form_data);
}

the routes.php,

Route::get('manage-forms',array('as'=>'manage_forms','uses'=>'Nri@manage_forms'));

the View file,

<title>Registered Form details</title>
<h2>Registered Form details</h2>

<ul>
@foreach($form_array as $form_view)
<li>{{$form_view->name}}</li>
@endforeach
</ul>

My Forms model (Form.php),

 <?php

 use Illuminate\Auth\UserTrait;
 use Illuminate\Auth\UserInterface;
 use Illuminate\Auth\Reminders\RemindableTrait;
 use Illuminate\Auth\Reminders\RemindableInterface;

 class Form extends Eloquent implements UserInterface, RemindableInterface {

use UserTrait, RemindableTrait;

/**
 * The database table used by the model.
 *
 * @var string
 */
protected $table = 'forms';

/**
 * The attributes excluded from the model's JSON form.
 *
 * @var array
 */
protected $hidden = array('password', 'remember_token');

}

I am getting error like

 BadMethodCallException

 Method all does not exist.
  • 写回答

1条回答 默认 最新

  • drd2551 2014-11-30 05:48
    关注

    You have to change your class name from Form to something else, as Form:: is already in use by laravel itself and you can't use the same class more than once

    Remember to run php artisan dump-autoload after changing

    Here:

    class Formdata extends Eloquent implements UserInterface, RemindableInterface {          
          // ^this needs to be changed 
    
    use UserTrait, RemindableTrait;
    
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'forms';
    
    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('password', 'remember_token');
    
    }
    

    and this:

    public function manage_forms()
    {
        $form_data=Formdata::all();
                    ^ and this
        return View::make('manage_forms')->with('form_array',$form_data);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,