我有這樣的代碼,當我嘗試訪問laravel.dev/cats/create出現一個頁面插入表:廣東話使用laravel
Route::model('cat', 'Cat');
Route::get('cats/create', function() {
$cat = new Cat;
return View::make('cats.edit')
->with('cat', $cat)
->with('method', 'post');
});
Route::post('cats', function(){
$cat = Cat::create(Input::all());
return Redirect::to('cats/' . $cat->id)
->with('message', 'Successfully created page!');
});
Route::get('cats/{id}', function($id) {
$cat = Cat::find($id);
return View::make('cats.single')
->with('cat', $cat);
});
,這是我的貓/ edit.blade.php代碼:
@extends('master')
@section('header')
<a href="{{('cats/'.$cat->id.'')}}">← Cancel </a>
<h2>
@if($method == 'post')
Add a new cat
@elseif($method == 'delete')
Delete {{$cat->name}}?
@else
Edit {{$cat->name}}
@endif
</h2>
@stop
@section('content')
{{Form::model($cat, array('method' => $method, 'url'=>
'cats/'.$cat->id))}}
@unless($method == 'delete')
<div class="form-group">
{{Form::label('Name')}}
{{Form::text('name')}}
</div>
<div class="form-group">
{{Form::label('Date of birth')}}
{{Form::text('date_of_birth')}}
</div>
<div class="form-group">
{{Form::label('Breed')}}
{{Form::select('breed_id', $breed_options)}}
</div>
{{Form::submit("Save", array("class"=>"btn btn-default"))}}
@else
{{Form::submit("Delete", array("class"=>"btn btn-default"))}}
@endif
{{Form::close()}}
@stop
我現在不哪裏出了問題,我有一個編輯相同的代碼刪除但這些傢伙正常工作,但這一個不!
這是一個調試器報告的錯誤:
Trying to get property of non-object (View: D:\Xampp\htdocs\laravel\app\views\cats\single.blade.php)
<?php echo e($cat->name); ?>
錯誤提及該行。
感謝您的幫助:))))
編輯: 這是single.blade.php:
@extends('master')
@section('header')
<?php// dd($cat); ?>
<a href="{{url('/')}}">Back to overview</a>
<h2>
{{{$cat->name}}}
</h2>
<a href="{{url('cats/'.$cat->id.'/edit')}}">
<span class="glyphicon glyphicon-edit"></span> Edit
</a>
<a href="{{url('cats/'.$cat->id.'/delete')}}">
<span class="glyphicon glyphicon-trash"></span> Delete
</a>
Last edited: {{$cat->updated_at}}
@stop
@section('content')
<p>Date of Birth: {{$cat->date_of_birth}} </p>
<p>
@if($cat->breed)
Breed:
{{link_to('cats/breeds/' . $cat->breed->name,
$cat->breed->name)}}
@endif
</p>
@stop
我不知道爲什麼,當我去的貓/創建我傳遞給single.blade.php我認爲這是我要去哪裏錯了,但不知道在哪裏代碼我這樣做
打開'app/config/app.php'中的調試,你會得到一個有用的錯誤信息 – RMcLeod 2014-10-16 11:16:37
謝謝你兄弟,非常有用 – Arman 2014-10-16 11:17:45
你能發佈整個錯誤嗎? – Jerodev 2014-10-16 11:29:23