我想在index.blade.php文件中添加编辑和删除链接,以便删除和编辑记录。
这是我的代码:
路线档案:
Route::get('/home', 'HomeController@index');
Route::get('/patient/emergency-contacts' , 'patient/EmergencyContacts@index' ) ;
Route::get('/patient/emergency-contacts/create' , 'patient/EmergencyContacts@create' ) ;
Route::get('/patient/emergency-contacts/{id}/edit', 'EmergencyContactsController@edit' ) ;
Route::post('/patient/emergencycontacts_store', ['uses' => 'EmergencyContactsController@store', 'as' => 'emergencycontacts_store']);
Route::get('/patient/emergencycontacts_delete/{id}','EmergencyContactsController@destroy' ) ;
Route::resource('/patient/emergency-contacts', 'EmergencyContactsController');
Index.blade.php:views / patient / emergencycontacts / index.blade.php - Path
@extends('layouts.master')
@section('content')
<div id="emer" class="tabcontent">
<h3>Emergency Contacts</h3>
@if(Session::has('message')) <div class="alert alert-info"> {{Session::get('message')}} </div> @endif
<ul>
@foreach($result as $error)
<li><div class="details"><label> Saluation</label><span>{{ $error->salutation }}</span></div>
<div class="details"><label> First Name</label><span>{{ $error->firstname }}</span></div>
<div class="details"><label> Last Name</label><span>{{ $error->lastname }}</span></div>
<div class="details"><label> Relationship</label><span>{{ $error->relationship }}</span></div>
<div class="details"><label> Phone</label><span>{{ $error->phone }}</span></div>
<div class="details"><label> Fax</label><span>{{ $error->fax }}</span></div>
{!! Form::open() !!}
{!! Form::submit('Edit', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}</li>
{!! Form::open() !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}</li>
@endforeach
</ul>
</div>
@stop
答案 0 :(得分:1)
你快到了......
// ASSUMING YOU HAVE THESE 2 ARBITRARY ROUTES ALREADY DEFINED:
Route::get('/patient/emergency-contacts/{id}/edit',
'EmergencyContactsController@edit',
['as' => 'emergencycontacts_edit']) ; );
Route::get('/patient/emergency-contacts/{id}/delete',
'EmergencyContactsController@delete',
['as' => 'emergencycontacts_delete']) ;
这里是你的刀片模板的基本内容......
@extends('layouts.master')
@section('content')
<div id="emer" class="tabcontent">
<h3>Emergency Contacts</h3>
@if(Session::has('message'))
<div class="alert alert-info">
{{Session::get('message')}}
</div>
@endif
<ul>
@foreach($result as $error)
<li>
<div class="details">
<label> Saluation</label>
<span>{{ $error->salutation }}</span>
</div>
<div class="details">
<label> First Name</label>
<span>{{ $error->firstname }}</span>
</div>
<div class="details">
<label> Last Name</label>
<span>{{ $error->lastname }}</span>
</div>
<div class="details">
<label> Relationship</label>
<span>{{ $error->relationship }}</span>
</div>
<div class="details">
<label> Phone</label>
<span>{{ $error->phone }}</span>
</div>
<div class="details">
<label> Fax</label>
<span>{{ $error->fax }}</span>
</div>
以下是您执行某些操作的地方:
<!-- ••••••••••••••••••••••••••••••••••••••••••••••• -->
<!-- ••••••••••••••••••••••••••••••••••••••••••••••• -->
<!-- ADD THE EDIT + DELETE LINKS USING NORMAL <A /> TAGS -->
<!-- & HREF TARGETING THE EDIT/DELETE LINKS RESPECTIVELY.-->
<!-- WHY USE A FORM? YOU JUST WANTED TO EITHER UPDATE OR -->
<!-- DELETE A RECORD WITH A SPECIFIC ID.... A LINK WILL DO -->
<!-- SURE; YOU'D NEED A FORM FOR THE UPDATE/EDIT PROCESS -->
<div class="actions">
<!-- HERE; YOU NEED A WAY TO OBTAIN THE contact_id -->
<!-- AGAIN WE PRESUME IT'S ACCESSIBLE VIA: -->
<!-- $error->contactId -->
<!-- YOU (AS THE PROGRAMMER) KNOW THIS BEST... -->
<a href="{{ route('emergencycontacts_edit', ['id' =>
$error->contactId]) }}"
class="btn btn-success" >
<i class="fa fa-pencil"></i> Edit
</a>
</div>
<div class="actions">
<a href="{{ route('emergencycontacts_delete', ['id' =>
$error->contactId]) }}"
class="btn btn-danger" >
<i class="fa fa-trash"></i> Delete
</a>
</div>
</li>
@endforeach