【发布时间】:2017-05-16 14:09:15
【问题描述】:
我使用 Laravel 创建了一个会议室预订系统。所以,我有 2 张桌子,这是 Auth::guest 预订房间的预订,以及 Auth::user 批准预订房间的活动。
如果 auth::user 为真,我有一个视图列出来宾 (/books) 进行的所有预订,在视图中,有一个批准按钮,它将带您进入另一个视图,即 (events /create) 与 (/books/create) 视图具有相同的形式。
当你点击批准按钮时,预订的所有数据都会出现在(events/create)中的表格中,因为我有预订数据的$id,所以我可以做Book::findOrfail($id ),当点击应用提交按钮时,数据将被保存到事件表中。
那么,我的问题是如何在我点击(事件/创建)视图上的提交按钮后自动从书表中删除预订数据?
有什么想法吗?
在事件控制器上创建事件
public function create_by_booking($id)
{
$event = Book::findOrFail($id);
$event->start_time = $this->change_date_format_fullcalendar($event->start_time);
$event->end_time = $this->change_date_format_fullcalendar($event->end_time);
$data = [
'page_title' => 'Add new event',
'event' => $event,
'count' => Book::count(),
];
return view('event/create', $data);
}
从书籍控制器创建书籍
public function create()
{
$data = [
'page_title' => 'Book Meeting Room',
'count' => Book::count(),
];
return view('book/create', $data);
}
查看列表/书籍
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Booking's Title</th>
<th>Email</th>
<th>Room</th>
<th>Start</th>
<th>End</th>
<th></th>
</tr>
</thead>
<tbody>
<?php $i = 1;?>
@foreach($books as $book)
<tr>
<th scope="row">{{ $i++ }}</th>
<td><a href="{{ url('books/' . $book->id) }}">{{ $book->title }}</a> <small>by {{ $book->name }}</small></td>
<td>{{ $book->email }}</td>
<td>{{ $book->room }}</td>
<td>{{ date("g:ia\, jS M Y", strtotime($book->start_time)) }}</td>
<td>{{date("g:ia\, jS M Y", strtotime($book->end_time)) }}</td>
@if (Auth::guest())
@else
<td>
<a class="btn btn-primary btn-xs" href="{{ url('/events/create', $book->id) }}">
<span class="glyphicon glyphicon-plus"></span> Add</a>
<form action="{{ url('books/' . $book->id) }}" style="display:inline" method="POST">
<input type="hidden" name="_method" value="DELETE" />
{{ csrf_field() }}
<button class="btn btn-danger btn-xs" type="submit"><span class="glyphicon glyphicon-trash"></span></button>
</form>
</td>
@endif
</tr>
@endforeach
</tbody>
</table>
谢谢。
【问题讨论】:
-
到目前为止,您是如何处理事件/创建视图的? - 我的意思是,控制器..
-
分享你的代码
-
已更新代码。
-
只传递一个记录的ID来创建事件,然后用这个ID删除它
标签: laravel