我有一个userDashboard()
函数,并且必须在此updateUserlocation()
函数内部调用userDashboard()
函数。
请告诉我该怎么做。
我尝试在updateUserLocation()
内添加userDashboard()
,但无法正常工作。
此错误即将到来:
调用未定义函数App \ Http \ Controllers \ userUpdateLocation()
这是userDashboard函数:-
public function userDashboard()
{
$user = Session::get('user_account');
$commonModel = new CommonModel();
$userModel = new User();
$data = $commonModel->commonFunction();
$login = GlobalData::isLoggedIn();
if ($login) {
return redirect(url('/'));
}
$data['user_session'] = Session::get('user_account');
// Get the groups joined by the user
$user_id = $data['user_session']['id'];
$get_groups = DB::table('trans_group_users')
->where('user_id_fk', $user_id)
->get();
// if user's group count is zero, redirect to signup2 to choose groups first
if (count($get_groups) == 0) {
Session::flash('error_msg', 'Please select atleast one group to proceed further.');
return redirect()->guest('/signup2');
}
$lang_id = 14;
$arr_user_data = array();
$user_id = $data['user_session']['id'];
/* Differciate date for get record for perticuler month */
$today_date = date("Y-m-d");
$first_date = date("Y-m-01");
$date1 = date_create($today_date);
$date2 = date_create($first_date);
$diff = date_diff($date1, $date2);
$remain_days = $diff->days;
$today_with_minus_days = date('Y-m-d', strtotime("-$remain_days days"));
/* Ends here */
/* notification count */
$arr_user_data = $userModel->find($user_id);
$arr_user_data = $arr_user_data;
$get_events = DB::table('mst_event as e')
->join('trans_event_rsvp_status as r', 'r.event_id_fk', '=', 'e.id')
->where('r.user_id_fk', $user_id)
->where('r.status', 1)
->where('e.start_date', '>', $today_with_minus_days)
->where('e.end_date', '<', $today_date)
->select('e.start_date')
->groupBy('e.id')
->get();
$get_e = array();
if (count($get_events) > 0) {
foreach ($get_events as $object) {
$get_e[] = (array) $object;
}
}
$get_meetups = DB::table('mst_meetup as m')
->join('trans_meetup_rsvp_status as r', 'r.meetup_id_fk', '=', 'm.id')
->where('r.user_id_fk', $user_id)
->where('m.start_date', '>', $today_with_minus_days)
->where('m.start_date', '<', $today_date)
->where('r.status', 1)
->select('m.start_date')
->groupBy('m.id')
->get();
$get_m = array();
if (count($get_meetups) > 0) {
foreach ($get_meetups as $object) {
$get_m[] = (array) $object;
}
}
$arr = array();
$arr = array_merge($get_e, $get_m);
$upcoming_going_event_count = count($arr);
if ($upcoming_going_event_count > 0) {
Session::put('going_count', $upcoming_going_event_count);
} else {
Session::forget('going_count');
}
/* Ends here */
$data['header'] = array(
"title" => 'My Home | ATG',
"keywords" => '',
"description" => ''
);
return view('Frontend.user.dashboard')
->with('title', 'Profile')
->with('finalData', $data)
->with('arr_user_data', $arr_user_data);
}
这是updateUserlocation
函数:-
public function updateUserLocation()
{
/* Update User Location based on input from the browser, else from IP */
$all = Input::all();
$latitude = (isset($all['latitude']) ? $all['latitude'] : '');
$longitude = (isset($all['longitude']) ? $all['longitude'] : '');
$agent = (isset($all['agent']) ? $all['agent'] : '');
$commonModel = new CommonModel();
$data = $commonModel->commonFunction();
$data['user_session'] = Session::get('user_account');
$user_id = $data['user_session']['id'];
if ($latitude == '' && $longitude == '') {
try {
$ip = Request::ip();
$data = \Location::get($ip);
$latitude = $data->latitude;
$longitude = $data->longitude;
$agent = $_SERVER['HTTP_USER_AGENT'];
} catch (\Exception $e) {
\Log::alert($e->getMessage());
\Log::debug($e);
}
}
$this->UpdateUserLocationfx($user_id, 'web', $latitude, $longitude, $agent);
}
答案 0 :(得分:1)
Laravel / PHP认为您正在调用类或控制器而不是方法。
如果userUpadateLocation()
方法与userDashboard()
在同一控制器内,请使用$this
变量从同一控制器内调用该方法:
$this->userUpadateLocation();
$this
转换为“使用此控制器的方法”。