【问题标题】:Creating default object from empty value for information从空值创建默认对象以获取信息
【发布时间】:2019-07-09 12:34:54
【问题描述】:

我正在尝试编辑和保存一些文章,但收到此错误:Creating default object from empty value。我的代码有什么问题?因为在编辑时我有我的subject,但是提交后我得到了这个错误。 我的错误: https://imgur.com/a/eWGqc5B 控制器

public function update($type, $id)

    {
        /* print_r(Input::all()); die;  */
        if($type == "News")
        {
            $article = \App\News::find($id);
            $article->subject = Request::input('subject');
            $article->public = Request::input('public');
            $article->category_id = Request::input('category_id');
            $article->information = Request::input('information');
            $article->update();
        }


        if($type == "Event")
        {

            $article = \App\Event::find($id);
            $article->subject = Request::input('subject');
            $comm->comments = Request::input('comments');
            $article->public = Request::input('public');
            $article->category_id = Request::input('category_id');
            $article->event_type_id = Request::input('event_type_id');
            $article->country = Request::input('country');
            $article->starts = Request::input('starts');
            $article->ends = Request::input('ends');
            $article->organizer = Request::input('organizer');
            $article->address = Request::input('address');
            $article->city = Request::input('city');
            $article->website = Request::input('website');
            $article->email = Request::input('email');
            $article->telephone = Request::input('telephone');
            $article->information = Request::input('information');
            $article->update();


        }


        return redirect(URL::previous());

ArticleController.php 中的第 669 行 $article->subject = Request::input('subject');

这是我的 editEvent 代码:https://codepen.io/anon/pen/YodwKO

我的 articles.blade 代码:https://codepen.io/anon/pen/jjXWOb

我的路线: ` Route::post('admin/article/update/{type?}/{id?}', ['as' => 'update.article', 'uses' => 'ArticleController@update']);

`

【问题讨论】:

  • Line 669?但它是一个控制器... o.o |您在控制器中也有您的逻辑..应该在块中..
  • 我想$article = \App\News::find($id); 为空或为空。找不到新的 id = $id。之后转储您的文章,它将为空
  • 怎么转储呢?用 dd()?

标签: php database laravel


【解决方案1】:

变量 $comm 未定义。好像打错字了。

【讨论】:

  • $event_comm = EventComment::where('event_id', $id)->get();,我有这个,我应该写$event_comm而不是$comm?
  • 看起来你的意思是 $article 而不是 $comm
  • 不,兄弟,这里不应该是 $article,因为它来自另一个表。另请查看editArticle.blade /Articles.blade
猜你喜欢
  • 2020-04-09
  • 1970-01-01
  • 2021-02-22
  • 1970-01-01
  • 2015-01-28
  • 2017-11-29
  • 2017-09-30
  • 2016-08-18
  • 2018-07-18
相关资源
最近更新 更多