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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大