我正在开发一个简单的CRUD应用程序,我想从我的表单表中获取我的表单详细信息。
我的控制器如下所示,
public function manage_forms()
{
$form_data=Form::all();
return View::make('manage_forms')->with('form_array',$form_data);
}
路线.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>
我的窗体模型 (窗体.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 更改为其他名称,因为 Form::
已经被 laravel 本身使用,并且您不能多次使用同一个类
记得在更改后运行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);
}