红酒泡绿茶 2018-01-19 09:39
浏览 39

从视图调用函数并记录用户活动 - laravel

I'm having a problem with some users, and to discover the problem I want to record things, in views and controller.

I use:

Controller.php

public function records($user_id, $event_id, $action){

    $record = new Record();
    $record->user_id = $user_id;
    $record->event_id = $event_id;
    $record->action = $action;
    $record->save();
}

What I use in my controllers

$this->records(0, 0,'user in this step');   

What I'm trying in views.blade.php

{{\App\Http\Controllers\Controller::records(0, 0,'ajax success')}}

This returns the error: Non static method

{{\App\Http\Controllers\Controller->records(0, 0,'ajax success')}}

This returns the error: "->" unexpected operator

So How can I call the function? Probably it's easy but I'm new with Laravel.

Thanks

  • 写回答

1条回答 默认 最新

  • drrvnbwle80177811 2018-01-19 09:50
    关注
    You can call function from view like below.
    
    @php
    
    $controllerObj = new \App\Http\Controllers\Controller();
    $controllerObj->records(0, 0,'ajax success');
    
    @endphp
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分