laravel条件隐藏的字段 [英] laravel hidden fields on condition

查看:876
本文介绍了laravel条件隐藏的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为Vote_actions的数据库和模型,如下所示:

I have a database and model called Vote_actions that looks like this:

id

group_id

user_id

action_type

action_type

匿名(布尔值)

用户可以要求匿名(这将使布尔值成为true).如果是这种情况,我想将user_id从返回的模型更改为-1. 通常,将有多个行将被返回.那里我不想为函数中的每一行使用一个增幅器 laravel中有什么方法可以做到吗?

User can ask to be anonymous (that would make the boolean value to be true).If that is the case, I want to change the user_id from the returned model to -1. Usually, there will be multiple rows that will be returned. There I don't want to use a mutator for each row in the function Is there a way in laravel that I can do it ?

推荐答案

正如您所说的,您不想为此使用mutator.只需将匿名的user_id直接设置为-1,然后再保存到数据库即可.

as what you've said that you dont want to use the mutator for this. just set directly the user_id to -1 in your controller if anonymous before saving to DB.

这篇关于laravel条件隐藏的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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