[英]Laravel Fetching error from database Eloquent ORM
我正在开发一个简单的CRUD应用程序,我想从表单表中获取表单详细信息。
我的控制器如下图所示
public function manage_forms()
{
$form_data=Form::all();
return View::make('manage_forms')->with('form_array',$form_data);
}
route.php,
Route::get('manage-forms',array('as'=>'manage_forms','uses'=>'Nri@manage_forms'));
查看文件,
<title>Registered Form details</title>
<h2>Registered Form details</h2>
<ul>
@foreach($form_array as $form_view)
<li>{{$form_view->name}}</li>
@endforeach
</ul>
我的表单模型(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');
}
我收到类似的错误
BadMethodCallException
Method all does not exist.
您必须将类名从Form更改为其他名称,例如laravel本身已经在使用Form::
,并且您不能多次使用同一个类
记住在更改后运行php artisan dump-autoload
这里:
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');
}
和这个:
public function manage_forms()
{
$form_data=Formdata::all();
^ and this
return View::make('manage_forms')->with('form_array',$form_data);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.