簡體   English   中英

在laravel視圖中查看我的數據庫

[英]viewing my database in the view at laravel

很抱歉,如果這是一個新手Q ..但請幫助我解決此問題。 另外請告訴我為什么會發生此錯誤。

這是我的編輯視圖

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>

@停

這是我的表演視圖

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

在控制器中進行一些小的更改,請嘗試:)在您的代碼中,您沒有將變量“作者”發送到視圖中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM