[英]Passing data from view to view in laravel
I need to pass information from view to another view when pushing "Edytuj" button按下“Edytuj”按钮时,我需要将信息从视图传递到另一个视图
Here is my SlideController (secondView)这是我的 SlideController (secondView)
public function slideindex()
{
$list = Slide::all();
return view('slide-list', ["slidesList" => $list, "title" => "Slides index"
]);
My routes我的路线
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');
Blade of second view第二视角之刃
@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')
< <
It needs to be working same way when adding another records添加其他记录时,它需要以相同的方式工作
Next i will need to assign same ID to all new records in second view .接下来,我需要为第二个视图中的所有新记录分配相同的 ID。 In same ID i mean to send them ID that is corresponding to name that im trying to send在同一个 ID 中,我的意思是向他们发送与我尝试发送的名称相对应的 ID
There is couple of ways you can try有几种方法可以尝试
I think you want to pass the ID of the row you want to edit?我认为您想传递要编辑的行的 ID?
You could create a route and a controller for this.您可以为此创建一个路由和一个控制器。
For example:例如:
controller.php控制器.php
public function show($id)
{
// logic here
}
web.php网页.php
Route::get('/{id}', 'controller@show')->name('show.edit.form');
You could then create a link inside your forloop:然后,您可以在 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
If you want to show all slides corresponding to a presentation.如果要显示与演示文稿对应的所有幻灯片。 You could add a method inside your Presentation model:您可以在 Presentation 模型中添加一个方法:
public function slides()
{
return $this->hasMany(Slide::class, 'your_foreign_key');
}
Then if you pass a presentation to a view, you could do something like this:然后,如果您将演示文稿传递给视图,您可以执行以下操作:
@foreach ($presentation->slides as $slide)
// logic here
@endforeach
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.