select('action_log.*', 'action_log_types.*') ->join('action_log_types', 'action_log_types.id', '=', 'action_log.type_id') ->orderBy('action_log.created_at', 'DESC'); if ($joinUser) { $actions = $actions->join('users', 'users.id', '=', 'action_log.user_id') ->select('action_log.*', 'action_log_types.*', 'users.email', 'users.name as user_name'); } return $actions; } /** * Get last N user actions * * @param null $id * @param int $limit * * @return array */ public function getUserActions($id = null, $limit = 15) { // if user is not specified, use logged one if (is_null($id)) { $id = Auth::user()->id; } // load last N actions of selected user $actions = $this->getLogActionsQuery() ->limit($limit) ->where('user_id', $id) ->get(); // translate and return result $this->translateLogMessages($actions); return $actions; } /** * Method used for translating and filling parameters into value of log. * * @param $messages * * @return array */ public function translateLogMessages(&$messages) { // translate name and value of each record foreach ($messages as $i => $action) { $messages[$i]->name = trans($action->name); $messages[$i]->value = trans($action->value, (array)json_decode($action->parameters)); } } }