2014-06-25 32 views
0

對不起,如果這是一個非常新手Q .. 但請幫我解決這個問題。加給我,爲什麼這個錯誤發生的原因..查看我的數據庫在laravel的視圖

,這是我的編輯視圖

new.blade.php

@section('content') 
@include('common.show_error') 

{{Form::open(array('url'=>'author/update', 'method'=>'PUT'))}} 

<p> 
    {{ Form::label('name', 'Name: ') }}</br> 
    {{ Form::text('name', $author->name) }} 
</p> 

<p> 
    {{ Form::label('bio', 'Biography: ') }}</br> 
    {{ Form::textarea('bio', $author->bio) }} 
</p> 

{{ Form::hidden('id', $author->id) }} 

<p>{{ Form::submit('Edit Data') }}</p> 

@stop

,這是我的表演視圖

show.blade.php

@extends('layouts.default') 

@section('content') 
<h1>{{ $author->name }}</h1> 

<p>{{ $author->bio }}</p> 

<p>{{ $author->updated_at }}</p> 

<span> 
    {{ HTML::linkRoute('authors', 'Home') }} | 
    {{ HTML::linkRoute('edit_author', 'Edit', array($author->id)) }} | 
    {{ Form::open(array('url'=>'author/destroy', 'method'=>'DELETE', 'style'=>'display: inline;')) }} 
    {{ Form::hidden('id', $author->id) }} 
    {{ Form::submit('Delete') }} 
    {{ Form::close() }} 
</span> 
@stop 

這是我的控制器

public function update($id) 
{ 
    $id = Input::get('id'); 

    $validator = Member::validate(Input::all()); 

    if($validator->fails()){ 
     return Redirect::route('members.edit', $id)->withErrors($validator); 
    } else { 
     Member::where('id','=',$id)->update(array(
      'name' => Input::get('name'), 
      'bio' => Input::get('bio') 
     )); 

     return Redirect::route('members.show', $id) 
      ->with('message', 'Data Succesfully Updated'); 
    } 
} 

的情況:當我嘗試使用編輯按鈕編輯數據。它說:

「試圖獲得非對象laravel的財產」

,當我檢查的錯誤日誌。它指的是

<h1>{{ $author->name }}</h1> 
+1

Wheres顯示顯示頁面的控制器或路由?這可能是問題出現的地方 – KyleK

+0

你可以發佈你的代碼處理'members.edit'和'members.show'路由的控制器嗎? – Unnawut

回答

0
public function update($id) 
{ 
    $id = Input::get('id'); 

    $validator = Member::validate(Input::all()); 

    if($validator->fails()){ 
     return Redirect::route('members.edit', $id)->withErrors($validator); 
    } else { 
      $author = Member::find($id); 
      $author->update(array(
      'name' => Input::get('name'), 
      'bio' => Input::get('bio') 
     )); 

     return Redirect::route('members.show', $id) 
      ->with('message', 'Data Succesfully Updated') 
      ->with('author', $author); 
    } 
} 

在你的控制器變化不大,試試吧:)在你的代碼,你是不是送變量「作者」到您的視圖。