php - LARAVEL - 按钮更改数据库中的 bool 值

标签 php mysql laravel

当我点击成功按钮时,我必须将“confirmação”值更改为 1。

这可能吗? 我必须创建一个表单才能执行此操作?

 Schema::create('visitas', function (Blueprint $table) {
            $table->increments('id');
            $table->date('data');
            $table->time('hora');
            $table->boolean('confirmacao')->default(0);
            $table->integer('imovel_id');
            $table->integer('client_id');
            $table->timestamps();

Example

最佳答案

是的,您可以使用或不使用表格来完成此操作。但形式更好

<form method="post" action="/visitas">
    <input type="hidden" name="visitaID" value="$visita->id"/>
    <button class="btn btn-lg btn-success" type="submit">
        Confirmar Visita
    </button>
</form>

定义路线

Route::post('visitas', 'VistaController@update');

编写 Controller 的函数

public function update(Request $request)
{
    $visita = Visita::find($request->visitaID);
    $visita->confirmacao = 1;
    $visita->update();

    return redirect()->back()->with('message', 'visita updated');
}

这是一种方法。

关于php - LARAVEL - 按钮更改数据库中的 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42786333/

相关文章:

javascript - 有没有办法将菜单链接放到该菜单链接的子菜单中,并在您按下另一个选项之前保持选定的颜色?

php - 在shell中接收select的结果

python - 我该如何过滤 django 和 MySQL 数据库中的两个字段?

jquery - 为 Laravel Collective Form 创建手动提交按钮

php - Laravel Passport JWT 身份验证失败

php - WordPress 在循环外获取页面 ID

php - 在 PHP 中获取当前 Url 而不是文件根文件夹 url

php - Laravel:如何在 mac 上启动 redis?

php - 在 html 表格中将每条记录逐一显示

Mysql查询以查找附近重复的网址