Laravel 5 CRUD应用程序无法正常运行

时间:2017-03-12 14:52:12

标签: php laravel laravel-5 crud

我是Laravel的新手,但我必须通过创建表单创建填充段落中的空白。我需要的只是当我按下创建表单上的提交按钮时,这些参数应该填满这个index.blade.php的段落空白。请看这个。

@extends('layouts.app')
@section('content')
    @foreach($items as $item)
        <tr>
            <p>
                This is to hereby certify that, pursuant to ..... the Contract between ..... under the said
                contract,including all but not least, for ...... main and miscellaneous eqipment ..... have successfully
                supplied on dd/mm/yy
            </p>
        </tr>
    @endforeach
@endsection

这是我创建的index.blade.php

@extends('layouts.app')

@section('content')

    @foreach($items as $item)
        <tr>

            <p>
                This is to hereby certify that, pursuant to
                <td>{{ $item->po }}</td>
                the Contract between
                <td>{{ $item->company }}</td>
                under the said contract,including all but not least, for
                <td>{{ $item->boq_name }}</td>
                main and miscellaneous eqipment for
                <td>{{ $item->project_name }}</td>
                have successfully supplied on dd/mm/yy
            </p>

        </tr>
    @endforeach
@endsection

如果我通过创建函数创建新参数然后提交索引视图文件重复该段与填充空白。但我想要的是当我按提交保持段落相同但只需要更改参数。任何人建议应该去这里。

这是我的控制器功能

public function index()
{
    $items = SummeryForm::all();

    return view('summeryform/index', compact('items'));
}


public function create()
{
    return view('summeryform/create');
}


public function store(Request $request)
{
    $item = new SummeryForm;
    // $item ->id = Auth::user() ->id;
    $item ->po = $request ->po; 
    $item ->company = $request ->company;
    $item ->boq_name = $request ->boq_name;
    $item ->project_name = $request ->project_name;
    $item ->save();

    SummeryForm::create($request->all());

    return redirect()->route('summeryform.index')
                    ->with('success','Item created successfully');
}

谢谢。

1 个答案:

答案 0 :(得分:0)

我对您的问题不是很清楚,因为据我所知,您只需要在点击提交按钮后显示最后一个的一个段落。

如果我理解正确,您只需将索引方法更改为

public function index()
{
    $item = SummeryForm::all()->last();
    return view('summeryform/index', compact('item'));
}

和index.blade.php

@extends('layouts.app')
@section('content')
     <tr>
         <p>This is to hereby certify that, pursuant to <td>{{ $item->po }}</td>  the Contract  between <td>{{ $item->company }}</td> under the said contract,including all but not least, for <td>{{ $item->boq_name }}</td> main and miscellaneous eqipment for <td>{{ $item->project_name }}</td> have successfully supplied on dd/mm/yy</p>
    </tr>
@endsection