如何将所选条目保留在 table 中并在下一个视图中使用它?
How do I keep the selected entry in the table and use it on the next view?
大家好,我有一个 table 显示了一些关于演员的基本信息,如姓名、年龄等,在每个演员的右边我有三个按钮编辑、查看、删除。我的问题是,当我单击查看按钮时,我需要知道 table 中的哪个条目被选中进行查看,以便我可以显示信息。数据存储在 JSON 文件中,并通过控制器提取并传递到 blade.php 视图以显示在 table 中。
这是用于显示 table
中每个演员的代码
<a class="btn btn-primary" href="/actor/create" role="button">Actors</a>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Surname</th>
<th>Age</th>
<th>Nationallity</th>
<th>Options</th>
</tr>
</thead>
<tbody>
<?php foreach($jsonArray as $actor):?>
<tr>
<td> {{$actor['actorName']}}</td>
<td> {{$actor['actorSurname']}}</td>
<td> {{$actor['actorAge']}}</td>
<td> {{$actor['actorNationality']}}</td>
</td>
<td>
<a href="/actor/edit" class="btn btn-primary a-btn-slide-text">
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
<span><strong>Edit</strong></span>
</a>
<a href="/actor/show" class="btn btn-primary a-btn-slide-text">
<span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span>
<span><strong>View</strong></span>
</a>
<a href="#" class="btn btn-primary a-btn-slide-text">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
<span><strong>Delete</strong></span>
</a>
</td>
</tr>
<?php endforeach;;?>
</tbody>
</table>
So when the view is selected I need to know what actor so I can show the information of that actor to the user.我如何将它传递给下一个视图?
我的web.php文件
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/', function ()
{
return view('welcome');
});
Route::get ('actor/create',[ActorsController::class, 'createView']);
Route::post ('actor/create',[ActorsController::class, 'store'])->name('actor.store');
Route::get ('actor/edit',[ActorsController::class, 'edit']);
Route::get ('actor/index',[ActorsController::class, 'index']);
Route::get ('actor/show/{actorID}',[ActorsController::class, 'show']);
Route::get ("/director/create",[DirectorController::class, 'create']);
Route::post ('director/create',[DirectorController::class, 'store'])->name('director.store');
Route::get ("/director/edit",[DirectorController::class, 'edit']);
Route::get ("/director/index",[DirectorController::class, 'index']);
Route::get ("/director/show",[DirectorController::class, 'show']);
Route::get ("/genre/create",[GenreController::class, 'create']);
Route::post ("genre/create",[GenreController::class, 'store'])->name('genre.store');
Route::get ("/genre/edit",[GenreController::class, 'edit']);
Route::get ("/genre/index",[GenreController::class, 'index'])->name('genre.index');
Route::get ("/genre/show",[GenreController::class, 'show']);
Route::get ("/movie/create",[MovieController::class, 'create']);
Route::post ('movie/create',[MovieController::class, 'store'])->name('movie.store');
Route::get ("/movie/edit",[MovieController::class, 'edit']);
Route::get ("/movie/index",[MovieController::class, 'index']);
Route::get ("/movie/show",[MovieController::class, 'show']);
Route::get ("/nationallity/create",[NationalityController::class, 'createShow']);
Route::post ("/nationallity/create",[NationalityController::class, 'store'])->name('nationallity.store');
Route::get ("/nationallity/edit",[NationalityController::class, 'edit'])->name('nationallity.edit');
Route::get ("/nationallity/index",[NationalityController::class, 'index']);
Route::get ("/nationallity/show",[NationalityController::class, 'show']);
通常当你做一个基本的 crud 时,端点会是这样的:
baseURL/actor/IDActor (Edit PUT method)
baseURL/actor/IDActor) (Delete DELETE method)
baseURL/actor/IDActor (See data GET method)
在网页中可以这样做:
baseURL/actor/edit/IDActor (edit actor)
baseURL/actor/delete/IDActor) (delete actor)
baseURL/actor/IDActor (get actor info)
只需更改方法:
POST
for create, PUT
for modify, DELETE
for delete, GET
for get
data
关于方法的更多信息here
编辑视图调用数据库并显示数据。
如果您将其设置为您的编辑按钮:
<a href="/actor/edit/{{$actor['id']}}" class="btn btn-primary a-btn-slide-text">
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
<span><strong>Edit</strong></span>
</a>
删除或查看相同
你可以这样做:
将角色 id 传递给 url:<a href="/actor/show/{{ $actor['id] }}">
。
在 web.php
文件中定义此路由:
Route::get('/actor/show/{actor_id}', [ActorController::class, 'show'])
- 在
ActorController
中,从数据库中获取演员并将此数据发送到视图,就像您之前对演员列表所做的那样 table。
大家好,我有一个 table 显示了一些关于演员的基本信息,如姓名、年龄等,在每个演员的右边我有三个按钮编辑、查看、删除。我的问题是,当我单击查看按钮时,我需要知道 table 中的哪个条目被选中进行查看,以便我可以显示信息。数据存储在 JSON 文件中,并通过控制器提取并传递到 blade.php 视图以显示在 table 中。 这是用于显示 table
中每个演员的代码<a class="btn btn-primary" href="/actor/create" role="button">Actors</a>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Surname</th>
<th>Age</th>
<th>Nationallity</th>
<th>Options</th>
</tr>
</thead>
<tbody>
<?php foreach($jsonArray as $actor):?>
<tr>
<td> {{$actor['actorName']}}</td>
<td> {{$actor['actorSurname']}}</td>
<td> {{$actor['actorAge']}}</td>
<td> {{$actor['actorNationality']}}</td>
</td>
<td>
<a href="/actor/edit" class="btn btn-primary a-btn-slide-text">
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
<span><strong>Edit</strong></span>
</a>
<a href="/actor/show" class="btn btn-primary a-btn-slide-text">
<span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span>
<span><strong>View</strong></span>
</a>
<a href="#" class="btn btn-primary a-btn-slide-text">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
<span><strong>Delete</strong></span>
</a>
</td>
</tr>
<?php endforeach;;?>
</tbody>
</table>
So when the view is selected I need to know what actor so I can show the information of that actor to the user.我如何将它传递给下一个视图?
我的web.php文件
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/', function ()
{
return view('welcome');
});
Route::get ('actor/create',[ActorsController::class, 'createView']);
Route::post ('actor/create',[ActorsController::class, 'store'])->name('actor.store');
Route::get ('actor/edit',[ActorsController::class, 'edit']);
Route::get ('actor/index',[ActorsController::class, 'index']);
Route::get ('actor/show/{actorID}',[ActorsController::class, 'show']);
Route::get ("/director/create",[DirectorController::class, 'create']);
Route::post ('director/create',[DirectorController::class, 'store'])->name('director.store');
Route::get ("/director/edit",[DirectorController::class, 'edit']);
Route::get ("/director/index",[DirectorController::class, 'index']);
Route::get ("/director/show",[DirectorController::class, 'show']);
Route::get ("/genre/create",[GenreController::class, 'create']);
Route::post ("genre/create",[GenreController::class, 'store'])->name('genre.store');
Route::get ("/genre/edit",[GenreController::class, 'edit']);
Route::get ("/genre/index",[GenreController::class, 'index'])->name('genre.index');
Route::get ("/genre/show",[GenreController::class, 'show']);
Route::get ("/movie/create",[MovieController::class, 'create']);
Route::post ('movie/create',[MovieController::class, 'store'])->name('movie.store');
Route::get ("/movie/edit",[MovieController::class, 'edit']);
Route::get ("/movie/index",[MovieController::class, 'index']);
Route::get ("/movie/show",[MovieController::class, 'show']);
Route::get ("/nationallity/create",[NationalityController::class, 'createShow']);
Route::post ("/nationallity/create",[NationalityController::class, 'store'])->name('nationallity.store');
Route::get ("/nationallity/edit",[NationalityController::class, 'edit'])->name('nationallity.edit');
Route::get ("/nationallity/index",[NationalityController::class, 'index']);
Route::get ("/nationallity/show",[NationalityController::class, 'show']);
通常当你做一个基本的 crud 时,端点会是这样的:
baseURL/actor/IDActor (Edit PUT method)
baseURL/actor/IDActor) (Delete DELETE method)
baseURL/actor/IDActor (See data GET method)
在网页中可以这样做:
baseURL/actor/edit/IDActor (edit actor)
baseURL/actor/delete/IDActor) (delete actor)
baseURL/actor/IDActor (get actor info)
只需更改方法:
POST
for create,PUT
for modify,DELETE
for delete,GET
for get data
关于方法的更多信息here 编辑视图调用数据库并显示数据。
如果您将其设置为您的编辑按钮:
<a href="/actor/edit/{{$actor['id']}}" class="btn btn-primary a-btn-slide-text">
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
<span><strong>Edit</strong></span>
</a>
删除或查看相同
你可以这样做:
将角色 id 传递给 url:
<a href="/actor/show/{{ $actor['id] }}">
。在
web.php
文件中定义此路由:
Route::get('/actor/show/{actor_id}', [ActorController::class, 'show'])
- 在
ActorController
中,从数据库中获取演员并将此数据发送到视图,就像您之前对演员列表所做的那样 table。