public function postPost(Request $request) { $input = $request->all(); $rules = ['title' => ['max:20', 'required'], 'content' => ['min:10', 'required']]; $validator = Validator::make($input, $rules); $returnInf = []; if ($validator->fails()) { $messages = $validator->messages(); foreach ($array_dot($messages->toArray) as $value) { array_push($returnInf, $value); } Session::flash('operationResult', 'am-alert-warning'); Session::flash('returnInf', $returnInf); return redirect()->back()->withInput(Request::flash()); } else { $article = Article::create(['title' => $input['title'], 'content' => Common::encodeTopicContent($input['content']), 'node_id' => $input['node_id'], 'user_id' => $input['user_id']]); if ($article->id > 0) { array_push($returnInf, '发帖成功'); Session::flash('operationResult', 'am-alert-success'); Node::find($input['node_id'])->increment('article_count'); User::find($input['user_id'])->increment('article_count'); } else { array_push($returnInf, '我们的数据库出问题啦,请稍后再试=。='); Session::flash('operationResult', 'am-alert-warning'); } } Session::flash('returnInf', $returnInf); return redirect()->back(); }
public function getValues($values) { foreach ($values as $languageId => &$value) { $value = Node::find($value); } return $values; }
/** * Execute the console command. * * @return mixed */ public function fire() { //$nodes = \App\Node::where('poll_enabled', 'Y')->get(); $nodes = \App\Node::all(); foreach ($nodes as $node) { unset($exec_out1); exec('/usr/sbin/fping -e ' . $node->ip_address . ' 2>/dev/null', $exec_out1, $exec_ret1); if ($exec_ret1 == 0) { // ping ok $ping_success = 100; } else { // ping fail $ping_success = 0; } print $node->ip_address . ' = ' . $ping_success . '%' . PHP_EOL; $u_node = \App\Node::find($node->id); $u_node->ping_success = $ping_success; $u_node->save(); $ping = new \App\Ping(); $ping->node_id = $node->id; $ping->success = $ping_success; $ping->timestamp = \Carbon\Carbon::now(); $ping->save(); } }
public function create(urlRequest $request) { $node = Node::find($request->query('node_id')); $nodes = Node::allLevelUp(); SiteStatus::newTopic(); return view('topics.create_edit', compact('nodes', 'node')); }
public function updateData(array $data, $id) { $node = Node::find($id); $node->title = $data['title']; $node->description = $data['description']; $node->photo = $data['photo']; $node->save(); return $node; }
/** * Execute the console command. * * @return mixed */ public function fire() { // print \Carbon\Carbon::now() . ' Start snmpPoller...' . "\n"; $nodes = \App\Node::where('ping_method', 'ping')->where('ping_params', '')->where('ping_success', 100)->get(); $start_timestamp = time(); $counter = 0; foreach ($nodes as $node) { // try v2c $snmp = new \App\Lnms\Snmp($node->ip_address, $node->snmp_comm_ro, '2c'); $snmp->setOptions('-r 1 -t 1'); $get_result = $snmp->get(OID_sysUpTime); if ($get_result) { $snmp_version = 2; } else { // try v1 $snmp = new \App\Lnms\Snmp($node->ip_address, $node->snmp_comm_ro); $snmp->setOptions('-r 1 -t 1'); $get_result = $snmp->get(OID_sysUpTime); $snmp_version = 1; } if ($get_result) { // snmp ok $snmp_success = 100; $get_sysUpTime = $get_result[OID_sysUpTime]; // get sysObjectID $get_result2 = $snmp->get([OID_sysObjectID, OID_sysName]); $get_sysObjectID = $get_result2[OID_sysObjectID]; $get_sysName = $get_result2[OID_sysName]; } else { // snmp fail $snmp_version = 0; $snmp_success = 0; $get_sysUpTime = 0; $get_sysObjectID = ''; $get_sysName = ''; } $current_timestamp = time(); $diff_timestamp = $current_timestamp - $start_timestamp; print \Carbon\Carbon::now() . " {$counter} ({$diff_timestamp} s.) - {$node->ip_address} {$node->snmp_comm_ro} = (v{$snmp_version}) {$snmp_success} {$get_sysUpTime} = {$get_sysObjectID} {$get_sysName}\n"; $u_node = \App\Node::find($node->id); $u_node->snmp_version = $snmp_version; $u_node->snmp_success = $snmp_success; $u_node->snmp_updated = \Carbon\Carbon::now(); $u_node->sysObjectID = $get_sysObjectID; $u_node->sysName = $get_sysName; $u_node->sysUpTime = $get_sysUpTime; $u_node->save(); $counter++; } print \Carbon\Carbon::now() . ' Stop snmpPoller...' . "\n"; }
public function getnode($id = 0) { if (!$id) { throw new \Exception('Node ID is undefined'); } $current_node = Node::find((int) $id); $nodes_array = []; if ($current_node) { $getColumn = (new Node())->getAllColumnsNames(); //var_dump($getColumn); $fieldsValue = $current_node->toArray(); $nodes_array = array_map(function ($field) use($fieldsValue) { $field['value'] = $fieldsValue[$field['name']]; return $field; }, $getColumn); } return response()->json($nodes_array); }
public function postsList($nodeId = '') { $nodeIds = DB::table('node_hierarchy')->where('node_parent_id', '=', $nodeId)->lists('node_id'); $nodeIds = array_merge($nodeIds, [$nodeId]); $nodeIds = implode(',', $nodeIds); // if($nodeId==''){ // $posts = Post::paginate(10); // $node = ''; // }else{ $posts = Post::whereRaw("node_id in ({$nodeIds})")->orderBy('created_at', 'DESC')->paginate(6); $node = Node::find($nodeId); // } //dd(response()->json(view('home.post.posts',compact('posts'))->render())); if (Request::ajax()) { return response()->json(view('home.post.posts', compact('posts'))->render()); } return view('home.post.index', compact('posts', 'node')); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // $node = Node::find($id); $node->delete(); //同时更新子节点为顶级节点 $nodeIds = DB::table('node_hierarchy')->where('node_parent_id', '=', $id)->lists('node_id'); foreach ($nodeIds as $nodeId) { $node->children()->updateExistingPivot($nodeId, ['node_parent_id' => 0]); } flash()->success('删除成功'); return redirect()->back(); }
/** * Undo the deleted Element * * @param $id * @return \Illuminate\Http\RedirectResponse */ public function undoDelete($id) { $node = \App\Node::find($id); $node->deleted_at = null; $node->active = false; $node->save(); return redirect()->back(); }
public function create(Request $request) { $node = Node::find($request->input('node_id')); $nodes = Node::allLevelUp(); return view('topics.create_edit', compact('nodes', 'node')); }