Laravel 单击“审核”按钮后,自动删除旧数据

Laravel 单击“审核”按钮后,自动删除旧数据,laravel,Laravel,我使用Laravel创建了一个会议室预订系统。所以,我有两个表,一个是用于Auth::guest预订房间的book,另一个是用于Auth::user批准预订房间的event 如果auth::user为true,我可以列出来宾/图书所做的所有预订。在视图中,有一个approve按钮,它会将您带到另一个视图,即events/create,该视图与/books/create视图具有相同的形式 当您单击“批准”按钮时,预订的所有数据将显示在events/create中的表单中,因为我有预订数据的$id,

我使用Laravel创建了一个会议室预订系统。所以,我有两个表,一个是用于Auth::guest预订房间的book,另一个是用于Auth::user批准预订房间的event

如果auth::user为true,我可以列出来宾/图书所做的所有预订。在视图中,有一个approve按钮,它会将您带到另一个视图,即events/create,该视图与/books/create视图具有相同的形式

当您单击“批准”按钮时,预订的所有数据将显示在events/create中的表单中,因为我有预订数据的$id,因此我可以执行Book::findOrfail$id,当单击“应用提交”按钮时,数据将保存到事件表中

所以,我的问题是,在我点击events/create view上的submit按钮后,如何从book表中自动删除预订的数据

有什么想法吗

在事件控制器上创建事件

 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);
}
从书本控制器创建书本

 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>

谢谢。

我想你不是在问Laravel的技术人员如何删除一行

因此,一旦函数event/create成功,您应该调用该函数,例如delete_booking$id

但我的建议是,您不需要删除预订数据,而是在该行设置一个标志,指示预订已进入下一步


如果您正在考虑保存数据库大小,可以像每周一次那样批量删除,以清理预订表。依我看,这比一个接一个地自动执行更有效。

您已经在为视图传递$event变量,该变量包含您搜索的书籍的对象,因此我认为$event现在有一个id属性,您可以访问它

在事件/创建视图中,您可以编辑到store方法的路由以接受id,如下所示:

<form action="{{ url('/events/store', $data['event']->id) }}" method="POST">
 {{ csrf_field() }}
<button class="btn btn-danger btn-xs" type="submit"></button>
</form>
public function store($id) {  //of course edit your route to accept this variable

// here is where you process your events as you want.

$book = Book::find($id); //here is where you just find the book and delete it as you wanted.
$book->delete();

return redirect()->back();

}

到目前为止,您是如何处理事件/创建视图的?-我的意思是,控制器..使用代码共享您的代码更新。只需传递记录的ID以创建事件,然后使用此ID将其删除我想做的事情Book::find$ID->delete;存储功能成功后。如何将$id传递给store函数,以便我可以执行Book::find$id->delete?