使用Laravel Framework编辑表单

时间:2016-02-18 15:02:10

标签: php forms laravel

我是laravel的新手,并试图学习使用它。我为线程创建了一个小项目。没什么特别的。问题是,编辑某些东西的功能并不起作用,我不明白为什么。也许有人看到了这个错误?

那是我的路线:

Route::get('/index', 'Test\\TestController@index');
Route::get('/add', 'Test\\TestController@add');
Route::post('/test', 'Test\\TestController@store');
Route::get('/show/{id}', 'Test\\TestController@show');
Route::get('/show/{id}/edit', ['as' => 'edit', 'uses' => 'Test\\TestController@edit']);
Route::put('/show/{id}/edit', ['as' => 'editing', 'uses' => 'Test\\TestController@update']);

这是编辑方法的重要部分:

 public function edit($id) {
        $thread = Thread::query()->findOrFail($id);
        return view('test.edit', [
            'thread' => $thread
        ]);
    }

    public function update($id, StoreRequest $request) {
        $thread = Thread::query()->findOrFail($id);
        $thread->fill($request->all());
        $thread->save();
        return redirect(action('Test\\TestController@show', [$thread->id]));
    }
}

show.blade

@extends('master')
@section('content')
    <div class="panel panel-primary">
        <div class="panel-heading">
            <div class="panel-title">
                {{ $thread->thread }}
            </div>
        </div>
        <div class="form-body">
            <div class="form-group"><br>
                <ul>
                    {{$thread->content }}<br><br>
                    {{$thread->created_at->format('d.m.Y H:i:s')}}
                </ul>

            </div>
        </div>
        <div class="panel-footer">
           <a href="{{ URL::route('edit') }}"><div class="btn btn-primary">Thread bearbeiten</div></a>
        </div>
    </div>
@stop

编辑刀片(我要添加的文本位于文本框和保存按钮中的公式)

@extends('master')
@section('content')
    {!! Former::horizontal_open()->method('PUT')->action(action("Test\\TestController@update", [$thread->id])) !!}
    {!! Former::populate($thread) !!}
    {!! Former::text('thread')->label('Thread') !!}
    {!! Former::text("content")->label("Content") !!}
    {!! Former::large_primary_submit('Save!') !!}
    {!! Former::close() !!}
@stop

模特:

<?php
namespace App\Models\Thread;

use Illuminate\Database\Eloquent\Model;

class Thread extends Model {
    public $table = 'thread';
    public $fillable = [
        'thread',
        'content',
    ];
}

错误消息:

模型[App \ Models \ Thread \ Thread]没有查询结果。

0 个答案:

没有答案