繁体   English   中英

Laravel:从视图传递值到 controller

[英]Laravel : Passing value from view to controller

我的看法:

                        <table border="1" style="text-align: left;">

                        <td>
                            <b>Firstname</b>
                        </td>
                        <td>
                            <b>Actions</b>
                        </td>

                        @foreach($Newslist as $News)
                        <tr>
                        <td>
                         {{ $News->lastname }}   
                        </td>
                        <td>
                         <a href="/NewsEdit/{{$News->id}}/EditForm"><button type="button" class="btn btn-primary">Edit</button></a>  
                        </td>
                        </tr>
                        @endforeach

                </table>

我的路线/web.php:

Route::Post('NewsEdit/{{$News->id}}/EditForm','NewsControllere@EditForm');

我的 Controller.php:

<?php
namespace App\Http\Controllers;
use App\Newsmodel;
use Illuminate\Http\Request;

class NewsControllere extends Controller
{
    public function EditForm($NewsId)
    {   dd(request()->all());
        echo "deepakkeynes";exit();
        //$Newsmodel = Newsmodel::find($NewsId);

        //return view('/News')->with('News',$Newsmodel);
    }
}

单击视图中的编辑按钮时,会得到以下结果:结果: 404 页面预期结果:编辑按钮的 Id 以及回显值!

谁能帮我吗? 我是laravel的新手..!

看看这个关于Route Model Binding的 LaraCast 教程。 这很好地解释了底层文档

本质上:

路线/web.php:

Route::get('NewsEdit/{news}/EditForm','NewsControllere@EditForm');

新闻控制器.php:

public function EditForm(Newsmodel $news)
    {  
        return view('/News')->with('News',$news);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM