2

I have a function for userDashboard() and I have to call updateUserlocation() function inside this userDashboard() function.

Please tell me how to do that.

I have tried to add updateUserLocation() inside userDashboard() but it is not working.

This error is coming:

Call to undefined function App\Http\Controllers\userUpdateLocation()

This is the userDashboard function:-

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);
}

This is the updateUserlocation function:-

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);
}
1
  • Your error says userUpdateLocation. Your function is called updateUserLocation. Read the two closely. Commented Sep 29, 2019 at 19:30

1 Answer 1

1

Laravel / PHP thinks you are calling a class or controller instead of a method.

If the userUpadateLocation() method is within the same controller as userDashboard(), use the $this variable to call the method from within the same controller:

$this->userUpadateLocation();

$this translates to 'use this controller's method'.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.