按下“ Edytuj”按钮时,我需要将信息从一个视图传递到另一个视图
这是我的SlideController(secondView)
public function slideindex()
{
$list = Slide::all();
return view('slide-list', ["slidesList" => $list, "title" => "Slides index"
]);
我的路线
Route::get('index/createpresentation','DataController@createpresentation');
Route::post('index/','DataController@storepresentation');
Route::get('index/delete/{ID}','DataController@deletepresentation');
Route::get('index/edit/{ID}','SlideController@slideindex');
Route::get('index/','DataController@index');
Route::get('index/slideindex','SlideController@slideindex');
第二视图刀片
@extends('template')
@section('title'){{@title}} @endsection
@section('content')
<nav class="navbar fixed-top navbar-expand-lg navbar-light bg-light">
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="/index">Index <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="">Dodaj slajd <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<span class="navbar-brand ">Presentation Name</span>
</li>
</ul>
</div>
</nav>
<div class="container">
<table class="table table-hover">
<thead>
<tr>
<th>Id</th>
<th>Nazwa</th>
<th>Typ</th>
<th>Akcja</th>
</tr>
</thead>
<tbody>
@foreach ($slidesList as $slides )
<tr>
<th scope="row">{{$slides ->id}}</th>
<td>{{$slides->slideName}}</td>
<td>{{$slides->type}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection('content')
<< / p>
添加其他记录时,它必须以相同的方式工作
接下来,我将需要在第二个视图中为所有新记录分配相同的ID。在同一个ID中,我的意思是向他们发送与我要发送的名称对应的ID
答案 0 :(得分:0)
您可以尝试几种方法
答案 1 :(得分:0)
我认为您想传递要编辑的行的ID?
您可以为此创建一条路线和一个控制器。
例如:
controller.php
public function show($id)
{
// logic here
}
web.php
Route::get('/{id}', 'controller@show')->name('show.edit.form');
然后您可以在forloop内创建一个链接:
@foreach ($slidesList as $slides )
<tr>
<th scope="row">{{$slides ->id}}</th>
<td>{{$slides->slideName}}</td>
<td>{{$slides->type}}</td>
<td><a href="{{ route('show.edit.form', $slides->id) }}">EDIT</a></td>
</tr>
@endforeach
如果要显示与演示文稿相对应的所有幻灯片。 您可以在Presentation模型中添加一个方法:
public function slides()
{
return $this->hasMany(Slide::class, 'your_foreign_key');
}
然后,如果您将演示文稿传递给视图,则可以执行以下操作:
@foreach ($presentation->slides as $slide)
// logic here
@endforeach