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 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记