Php 从空值创建默认对象以获取信息
我正在尝试编辑和保存一些文章,但收到以下错误:Php 从空值创建默认对象以获取信息,php,database,laravel,Php,Database,Laravel,我正在尝试编辑和保存一些文章,但收到以下错误:从空值创建默认对象。我的代码出了什么问题?因为,在编辑时,我有我的主题,但是在提交时,我得到了这个错误。 我的错误: 控制器 public function update($type, $id) { /* print_r(Input::all()); die; */ if($type == "News") { $article = \App\News::find($i
从空值创建默认对象
。我的代码出了什么问题?因为,在编辑时,我有我的主题
,但是在提交时,我得到了这个错误。
我的错误:
控制器
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')代码>
这是我的编辑事件代码:
我的文章。刀片代码:
我的路线:
`
路由::post('admin/article/update/{type?}/{id?}',['as'=>'update.article','uses'=>'ArticleController@update']);
`未定义变量$comm。看起来像是打字错误。第669行
?但它是一个控制器。。。o、 o |控制器中也有逻辑。。应该在块中..我想$article=\App\News::find($id)代码>为null或空。找不到id为$id的新代码。转储你的文章后,它将是空的如何转储它?使用dd()?$event\u comm=EventComment::where('event\u id',$id)->get()代码>,我有这个,我应该写$event\u comm
而不是$comm?
看起来你的意思是$article而不是$commno bro,这里不应该是$article,因为它来自另一个表。还请检查editArticle.blade
/Articles.blade