php - 如何在 Laravel 5 上添加警报?

标签 php laravel laravel-5

我有一个函数,其中:
单击名为"hapus" 的链接后,相关数据将被删除,我希望弹出警报以显示数据已被删除。

*对不起我的英语不好

*hapus 在技术上意味着摧毁

这是代码:

public function hapus(Request $request, $id)
    {
        DB::table('kelompok')
        ->where('id', $id)
        ->delete();
        return redirect()->back();
    }

最佳答案

使用with()在你的 Controller 中

 function hapus(Request $request, $id)
        {
            DB::table('kelompok')
            ->where('id', $id)
            ->delete();
            return redirect()->back()->with('alert', 'Deleted!');
        }

在您的 Blade 模板中,从 Controller 重定向后检索 session :

@if (session('alert'))
    <div class="alert alert-success">
        {{ session('alert') }}
    </div>
@endif

关于php - 如何在 Laravel 5 上添加警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38764421/

相关文章:

laravel - 如何在 Vue 3 中重定向另一个路由器? (在 Laravel 8 和 vue 3 中使用 next.router)

php - 在数据库中自动创建数据

php - 如何将随机字符串列添加到 laravel 迁移

php - CodeIgniter 身份验证、权限和管理系统,或 Django 的任何其他 PHP 等价物?

php - 使用 PHPUnit 测试 PHP header

php - 更新存折错误 - 无法读取通行证,因为它无效

php - 根据稀有度创建 "deck of cards"

php - laravel 多选表单获取数组

laravel - 将 Laravel Test 7 和 Laravel Passport 9.3 与个人访问客户端一起使用会给出异常 "Trying to get property ' id' of non-object"

php - 如何将请求实例从一个 Controller 函数传递到另一个 Controller 函数