php - Laravel 重定向数据不起作用

标签 php laravel laravel-blade

我的应用程序是一个简单的 CRUD 应用程序。我有一个删除 Controller 操作,当项目成功删除时,该操作会重定向回列表。我现在尝试添加的是向用户发送一条消息,表明数据已成功删除。

我的 Controller 操作:

public function deleteItem($id)
{
    try {
        $item = Item::findOrFail($id);
        $item->delete();
        return Redirect::to('list')->with('message', 'Successfully deleted');
    } catch (ModelNotFoundException $e) {
        return View::make('errors.missing');
    }
}

list.blade.php View 中我尝试显示消息的部分:

@if (isset($message))
    <div class="alert alert-success alert-dismissable">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
        {{ $message }}
    </div>
@endif

我遇到的问题是 $message 变量始终为空..

最佳答案

由于 with 方法将数据闪现到 session 中,因此您可以使用典型的 Session::get 方法检索数据。

所以你必须得到

$message = Session::get('message');

关于php - Laravel 重定向数据不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21644524/

相关文章:

laravel - anchor 标记在 Laravel 5.2 上不起作用

javascript - PHP/Ajax : How to show/hide DIV on $_SESSION variable value?

php - 扩展我在数据库编程方面的知识

php - 我可以为不同的类别设置不同的颜色吗

php - laravel - 无法在 Controller 构造函数中获取 session

php - laravel 如何指定输入列

php - 如何编写使用 PHP 变量的 MySQL 查询?

php - Laravel:检查 Controller 上的数据是否为整数

php - 从类名创建对象在命名空间中不起作用

Laravel Blade 指令添加额外的引号