Laravel :(会话?)将值从管理端传递给用户 [英] Laravel: (Session?) Pass value from admin side to user

查看:58
本文介绍了Laravel :(会话?)将值从管理端传递给用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在admin.blade页面中有一个名为目标"的值,可以由登录的管理员更改.我希望能够在用户页面(user.blade)上传递该新值. (没有注册用户,只有普通用户访问该页面).目前,我能够在管理页面上反映出更改,但是我无法将值传递给用户页面(可能是由于auth).我尝试了其他方法,但无法获得所需的信息.以下是我更改目标"值时会更新的函数:

I have a value called 'goal' in admin.blade page that can be changed by the admin who is logged in. I want to be able to pass that new value on a user's page(user.blade). (There is no registered user, just a normal user accessing the page). Currently, I am able to reflect the change on the admin page, but I cannot pass the value to the user page (probably because of auth).I have tried different ways but couldn't get what i wanted. Below is the function that updates the 'goal' value when i change it:

public function changeGoal(Request $data){

auth()->user()->update([
            'goal' => $data->input('newGoal')

        ]);

        return redirect('/adminpage');
}

使用此功能,当我键入{{$ goal}}时,它将在管理页面中显示已更改的值(对于已登录的管理员.)因此,现在,管理员可以更改该值并查看新的值.

Using this function, when i type {{$goal}}, it shows the changed value in the admin page(for a logged in admin.).So, right now, the admin can change the value and see the new value.

我希望由admin更改的值显示在用户页面中 (user.blade).我该如何实现?

I want the value changed by admin to show up in the user's page (user.blade). How can I achieve that?

有人建议我使用会话,但是它没有用,或者我做错了(即使我尝试从laravel文档中进行操作,也无法真正找到正确的方法). 我们将不胜感激.

I was suggested using session, but it didn't work, or maybe I did something wrong (even though I tried to do it from the laravel documentation, couldn't really figure it out properly). Help would be appreciated.Thanks

推荐答案

请勿将goal附加到您的User模型.也许您可以创建一个具有goal属性的SiteData模型.然后,在您的user.blade.php文件中,您可以通过以下方式检索goal:

Don't attach goal to your User model. Maybe you can create a SiteData model, which has a goal attribute. Then in your user.blade.php file you can retrieve goal by:

{{ SiteData::first()->goal }}

并让管理员对其进行更新:

And for admin to update it:

SiteData::first()->update(['goal' => 1000]);

希望有帮助!

这篇关于Laravel :(会话?)将值从管理端传递给用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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