我的视图包含两个元素:
add
按钮我想要做的是当我点击add
按钮时,它会显示一个带有表单的模式(lastname
,firstname
,role
,login
等等)
当我点击edit
按钮(表格中的行)时,它会打开相同的模态,但会在表单中显示用户的所有属性。
我的观点Users.blade.php
....
// include modal
@include('CreateOrEditModal', array('user' => isset($user) ? $user: null))
// add button
<button data-toggle="modal" data-target="#create_edit_modal" class="btn btn-primary"><i class="fa fa-plus"></i> Add user</button>
...
...
<tbody>
@foreach($users as $user)
<tr>
<td>{{$user->lastname}}</td>
<td>{{$user->firstname}}</td>
<td>{{$user->role}}</td>
<td>{{$user->login}}</td>
<td>{{$user->password}}</td>
<td>
<button class="btn btn-primary" data-target="#create_edit_modal" data="{{$user}}"><span class="fa fa-pencil"></span>Edit</button>
</td>
</tr>
@endforeach
</tbody>
我的模态
<div class="modal hide fade" id="create_edit_modal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog" >
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
@if(isset($user))
<h4 class="modal-title">{{$user->name}}</h4>
@else
<h4 class="modal-title">Add a new user</h4>
@endif
</div>
<div class="modal-body">
@if(isset($user))
{!! Form::model($user, array('class' => 'form-horizontal','route' => array('site.update', $user->id), 'method' => 'PUT')); !!}
@else
{!! Form::open(array('url' => 'site','class' => 'form-horizontal')) !!}
@endif
<div class="row">
....