0

剧情来了!!!

( 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() }}  

谢谢并恭祝安康

4

3 回答 3

0

您是否将您的迁移工作流程命名为工作流程?您的迁移可能与您的模型具有相同的类名。

于 2013-12-23T12:37:31.413 回答
0

问题解决了!问题是模型名称“WorkProcess”与我的视图名称 workprocess.blade.php”发生冲突。所以我将模型名称更改为“WPModel”,现在它工作正常。

于 2013-12-28T08:34:17.430 回答
0

以防您执行更改类名之类的操作。

假设您将模型的类名从 ' users' 更改为 ' user',

您可以尝试运行命令“ composer dump-autoload”。

尽管我的情况与您的情况不完全相同,但它对我有用。

于 2014-10-27T11:20:27.997 回答