剧情来了!!!
( work_processes ) 的架构
Schema::create('work_processes', function($table){
$table->increments('id');
$table->enum('wp_type',array('M','F','D')); //M => Maintenance, F => Field, D => Drilling
$table->string('wp_name',50);
$table->integer('wp_owner_id');
$table->integer('wp_editor_id');
$table->text('wp_link');
$table->enum('wp_frequency',array('B','M','Q')); //B => Bi-Monthly, M => Monthly, Q => Quarterly
$table->date('wp_startdate');
$table->date('wp_enddate');
$table->enum('wp_active',array('Y','N'));
$table->timestamp('deleted_at')->nullable();
$table->timestamps();
});}
( wp_audit_questions ) 的架构
Schema::create('wp_audit_questions', function($table){
$table->increments('id');
$table->integer('wp_id');
$table->text('wp_audit_question');
$table->timestamps();
});
模型 1 为 ( WorkProcess )
class WorkProcess extends Eloquent
{
protected $table = 'work_processes';
protected $guarded = array('id');
protected $softDelete = true;
public function wpauditquestions()
{
return $this->hasMany('WpAuditQuestion');
}
}
模型 2 为 ( WpAuditQuestion )
class WpAuditQuestion extends Eloquent
{
protected $table = 'wp_audit_questions';
public function workprocess()
{
return $this->belongsTo('WorkProcess', 'wp_id');
}
}
'控制器为(WorkProcessController)
class WorkProcessController extends BaseController
{
public function ShowWpAuditQuestionEditForm($wpid)
{
$wp = WorkProcess::with(array('wpauditquestions' => function($query){
$query->where('wp_id', $wpid);
}))->get();
return View::make('wpauditquestion')->with(array('edit_mode' => 1, 'wpauditquestion' => $wpauditquestion));
}
}
'控制器为(WpAuditQuestionController)
class WpAuditQuestionController extends BaseController
{
public function ShowWPAuditQuestionForm()
{
$wpauditquestion = new WpAuditQuestion();
return View::make('wpauditquestion', compact('wpauditquestion'));
}
}
路由.php
//model binding
Route::model('workprocess', 'WorkProcess');
Route::model('wpauditquestion', 'WpAuditQuestion');
Route::get('wpauditquestion/edit/{wpid}', array('uses' => 'WorkProcessController@ShowWpAuditQuestionEditForm', 'as' => 'wpauditquestion.edit'));
问题:
此脚本生成此错误消息。例如 MY_SERVER/wpauditquestion/edit/1
Symfony\Component\Debug\Exception\FatalErrorException
无法重新声明类 WorkProcess
但是,当我不使用 get() 或任何其他方法(如 paginate(5) 等)时,它确实会转储一些数据。
我也试过这个,但结果相同。
$wp = WorkProcess::has('wpauditquestions')->get();
有人可以指导我做错了什么。我将 laravel 4.0.7 与 WAMP 一起使用。
另外请指导我如何在编辑后保存此模型,例如,如果我有这样的表格。
{{ Form::open(array('action' => 'WorkProcessController@PostWorkProcessEditForm', 'method' => 'put')) }}
{{-- Work Process Name --}}
{{ Form::hidden('wp_id') }}
<ol>
@for($i = 0; $i < 5; $i++)
<p>
<li>
{{ Form::label('wp_audit_question', 'Audit Question') }}
{{ Form::text('wp_audit_question', Input::old('wp_audit_question')) }}
</p>
@endfor
</ul>
<p>{{ Form::submit('Submit Form', array('id' => 'Submit_Form')) }}</p>
{{ Form::close() }}
谢谢并恭祝安康