在laravel中发送数据进行重定向 [英] Redirecting with sending Datas in laravel

查看:69
本文介绍了在laravel中发送数据进行重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下代码:如果用户的登录信息不正确,则使用以下消息将用户再次重定向至腰部页面:

I tried following code: if the user's info to login is not correct redirect the user to the loin page again with the a message:

if (!$info_is_correct){
    $_SESSION['err_msg'] = 'your login info is not correct';
    return redirect('http://localhost:8000/user/login');
}

这是我在登录页面(视图)中执行的操作,以回显错误消息:

this is what I do in the login page(view) to echo the error msg:

    @isset($_SESSION['err_msg'])
        <div class="alert alert-danger mt-2" style="font-family:IRANSans;font-size:16px ;">
            <p>
                <strong>خطا !</strong>
                {{$_SESSION['err_msg']}}
                <?php unset($_SESSION['err_msg']) ?>

            </p>
        </div>
    @endisset

问题出在哪里?以及通过重定向发送数据以查看数据的最佳方法是什么?

where is the problem? and What is the best way to send data to view with redirecting?

推荐答案

使用 with() 方法:

return redirect('http://localhost:8000/user/login')->with('err_msg', 'your login info is not correct');

如果有视图:

@if (session('err_msg'))
    <div>{{ session('err_msg') }}</div>
@endif

这篇关于在laravel中发送数据进行重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆