程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Laravel - 如果 company_id 不存在,如何在日志活动中将零设置为默认值大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Laravel - 如果 company_id 不存在,如何在日志活动中将零设置为默认值?

开发过程中遇到Laravel - 如果 company_id 不存在,如何在日志活动中将零设置为默认值的问题如何解决?下面主要结合日常开发的经验,给出你关于Laravel - 如果 company_id 不存在,如何在日志活动中将零设置为默认值的解决方法建议,希望对你解决Laravel - 如果 company_id 不存在,如何在日志活动中将零设置为默认值有所启发或帮助;

在我的 Laravel-8 用户日志活动中,我有以下代码:

public static function addTolog($subject,$logtype=null,$subjecthint=null)
{
    $log = [];
    $log['subject'] = $subject;
    $log['log_type'] = $logtype;
    $log['subject_hint'] = $subjecthint;
    $log['log_url'] = request::fullUrl();
    $log['log_method'] = request::method();
    $log['ip_address'] = request::ip();
    $log['agent'] = request::header('user-agent');
    $log['user_iD'] = auth()->check() ? auth()->user()->ID : 1;
    $log['company_ID'] = auth()->user()->company_ID;
    $log['created_at'] = date("Y-m-d H:i:s");
    LogActivitymodel::create($log);
}

在 $log['company_ID'] = auth()->user()->company_ID;

当登录的用户不属于任何公司时,如何使 company_ID = 0?

谢谢

解决方法

如果你愿意,你可以使用其中之一

ERROR: Could not find a version that satisfies the requirement requests ERROR: No matching diStribution found for requests

ERROR: Could not find a version that satisfies the requirement numpy==1.16.2 ERROR: No matching diStribution found for numpy==1.16.2

$log['company_id'] = auth()->check() ? (auth()->user()->company_id ?? 0) : 0;

大佬总结

以上是大佬教程为你收集整理的Laravel - 如果 company_id 不存在,如何在日志活动中将零设置为默认值全部内容,希望文章能够帮你解决Laravel - 如果 company_id 不存在,如何在日志活动中将零设置为默认值所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。