[英]Laravel : Passing value from view to controller
My View:我的看法:
<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>
My routes/web.php:我的路线/web.php:
Route::Post('NewsEdit/{{$News->id}}/EditForm','NewsControllere@EditForm');
My Controller.php:我的 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);
}
}
While clicking the edit button in the view, the following result is obtained: Result: 404 page Expected Result: The Id of the edit button along with the echo value!单击视图中的编辑按钮时,会得到以下结果:结果: 404 页面预期结果:编辑按钮的 Id 以及回显值!
Can anyone help me out?谁能帮我吗? I am a newbie in laravel..!
我是laravel的新手..!
Have a look at this LaraCast tutorial on Route Model Binding .看看这个关于Route Model Binding的 LaraCast 教程。 This explains the underlying documentation well.
这很好地解释了底层文档。
Essentially:本质上:
routes/web.php:路线/web.php:
Route::get('NewsEdit/{news}/EditForm','NewsControllere@EditForm');
newsController.php:新闻控制器.php:
public function EditForm(Newsmodel $news)
{
return view('/News')->with('News',$news);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.