2017-01-02 24 views
2

私はlaravel 5.1で作業しています。 Model.phpライン2673で関係メソッドは、Laravel FormBuilderの型のオブジェクトを返す必要があります

LogicException:私は次のエラーを取得していますEDIT機能で 関係法は、タイプを照らし\データベースのオブジェクトを返す必要がありますが、\雄弁\リレーションズ\関係

は、ここで私のコントローラであり、機能:

public function edit(FormBuilder $formBuilder, $id) { 
    $result = News::findOrFail($id); 
    $form = $formBuilder->create('employment_bank\Forms\NewsForm', [ 
     'method' => 'PUT', 
     'model' => $result, 
     'url' => route($this->route.'update', $id) 
    ])->remove('save'); 
    return view($this->content.'edit', compact('form')); 
} 

ニュースモデル:

protected $table = 'news'; 
public static $rules = [ 
    'title' => 'required', 
]; 

protected $guarded = ['id', '_token']; 
protected $fillable = ['title', 'photo', 'status', 'summary', 'description', 'news_category_id', 'slug']; 
public $timestamps = true; 

public function news_category(){ 
    return $this->belongsTo('employment_bank\Models\NewsCategory', 'news_category_id'); 
} 

そして、形式は次のとおりです。フルで

public function buildForm(){ 

    $category = NewsCategory::lists('title', 'id')->all(); 
    $status = array(1 => "Publish",0 => "Draft"); 

    $this->add('title', 'text', [ 
     'attr' => ['required', 'maxlength' => '255', 'placeholder'=> 'News title'], 
     'wrapper' => ['class' => 'form-group'] // Shows the wrapper for each e 
    ]); 
    $this->add('photo', 'file', [ 
     'attr' => ['id' => 'photo_url', 'accept'=>'.jpg, .png', 'title'=>'Please upload a passport size photograph'], 
     'label' => 'Photo' 
    ]); 
    $this->add('news_category_id', 'select', [ 
     'choices' => $category, 
     'empty_value' => '==== Select Category ===', 
     'label' => 'Category', 
     'attr' => ['required'], 
    ]); 
    $this->add('status', 'select', [ 
     'choices' => $status, 
     'empty_value' => '==== Status ===', 
     'label' => 'status', 
     'attr' => ['required'], 
    ]); 
    $this->add('summary', 'textarea', [ 
     'attr' => ['maxlength' => '255', 'rows' => '5', 'placeholder'=> 'News summary'], 
     'wrapper' => ['class' => 'form-group'] // Shows the wrapper for each e 
     //'wrapper' => ['class' => 'form-group col-md-6'] // Shows the wrapper for each e 
    ]); 
    $this->add('description', 'textarea', [ 
     'attr' => ['rows' => '10', 'placeholder'=> 'News description'], 
     'wrapper' => ['class' => 'form-group'] // Shows the wrapper for each e 
     //'wrapper' => ['class' => 'form-group col-md-6'] // Shows the wrapper for each e 
    ]); 

    $this->add('save', 'submit', [ 
     'attr' => ['class'=>'btn btn-lg btn-primary col-md-12'] 
    ]); 

    $this->add('update', 'submit', [ 
     'attr' => ['class'=>'btn btn-lg btn-success col-md-12'] 
    ]); 
} 

エラー:私は間違って

LogicException in Model.php line 2673: 
Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation 
in Model.php line 2673 
at Model->getRelationshipFromMethod('save') in Model.php line 2643 
at Model->getRelationValue('save') in Model.php line 2585 
at Model->getAttribute('save') in Model.php line 3339 
at Model->__get('save') in Model.php line 3411 
at Model->__isset('save') in helpers.php line 529 
at object_get(object(News), 'save') in FormField.php line 191 
at FormField->getModelValueAttribute(object(News), 'save') in FormField.php line 113 
at FormField->setupValue() in FormField.php line 100 
at FormField->__construct('save', 'submit', object(NewsForm), array('attr' => array('class' => 'btn btn-lg btn-primary col-md-12'), 'real_name' => 'save')) in Form.php line 161 
at Form->makeField('save', 'submit', array('attr' => array('class' => 'btn btn-lg btn-primary col-md-12'))) in Form.php line 185 
at Form->add('save', 'submit', array('attr' => array('class' => 'btn btn-lg btn-primary col-md-12'))) in NewsForm.php line 46 
at NewsForm->buildForm() in FormBuilder.php line 53 
at FormBuilder->create('employment_bank\Forms\NewsForm', array('method' => 'PUT', 'model' => object(News), 'url' => 'http://localhost:8000/master/news/1')) in NewsController.php line 104 
at NewsController->edit(object(FormBuilder), '1') 
at call_user_func_array(array(object(NewsController), 'edit'), array(object(FormBuilder), 'news' => '1')) in Controller.php line 256 
at Controller->callAction('edit', array(object(FormBuilder), 'news' => '1')) in ControllerDispatcher.php line 164 
at ControllerDispatcher->call(object(NewsController), object(Route), 'edit') in ControllerDispatcher.php line 112 
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114 
at ControllerDispatcher->callWithinStack(object(NewsController), object(Route), object(Request), 'edit') in ControllerDispatcher.php line 69 
at ControllerDispatcher->dispatch(object(Route), object(Request), 'employment_bank\Http\Controllers\Master\NewsController', 'edit') in Route.php line 203 
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134 
at Route->run(object(Request)) in Router.php line 708 
at Router->Illuminate\Routing\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AuthenticateAdmin.php line 33 
at AuthenticateAdmin->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(AuthenticateAdmin), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 
at Pipeline->then(object(Closure)) in Router.php line 710 
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 675 
at Router->dispatchToRoute(object(Request)) in Router.php line 635 
at Router->dispatch(object(Request)) in Kernel.php line 236 
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50 
at VerifyCsrfToken->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49 
at ShareErrorsFromSession->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62 
at StartSession->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37 
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59 
at EncryptCookies->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44 
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 
at Pipeline->then(object(Closure)) in Kernel.php line 122 
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87 
at Kernel->handle(object(Request)) in index.php line 54 
at require_once('/var/www/jobportal/public/index.php') in server.php line 21 

をしていますか?

答えて

1

NewsFormでは、2つのボタン(保存および更新)をキーワードとして扱いました。

$this->add('save', 'submit', [ 
    'attr' => ['class'=>'btn btn-lg btn-primary col-md-12'] 
]); 

$this->add('update', 'submit', [ 
    'attr' => ['class'=>'btn btn-lg btn-success col-md-12'] 
]); 

ニュースと更新ニュースには、私のために働いた更新保存保存にボタンを変更します。

0

あなたのアプリのどこかのように、モデルインスタンス上に存在しないメソッドにアクセスしようとしています。そのため、関係を検索しています。

エラーの完全なスタックトレースを投稿できますか?

+0

あなたのレスポンスマンに感謝します。私は問題を発見した。 – shoeab

関連する問題