public function store() { /*$link = Link::where('url',Input::get('url'))->first(); if(!$link){ $link = Link::create(['url'=> Input::get('url')]); }*/ $link = Link::firstOrCreate(['url' => Input::get('url')]); return view('links.success', compact('link')); }
/** * Store a newly created resource in storage. * * @param AddUrlRequest|Request $request * @return Response */ public function store(AddUrlRequest $request) { //get url $url = $request->input('url'); //create or get from DB if url exists already $link = Link::firstOrCreate(['url' => $url]); //if url created than assign a hash if (!$link->hash) { $link->hash = str_random(7); $link->save(); } return \Redirect::home()->with('message', route('go', ['hash' => $link->hash]))->withInput(); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { $link = $request->all(); $linkInform = file_get_html($link['link']); $data['link'] = $link['link']; $data['user_id'] = $request->user()->id; $data['title'] = $linkInform->find('title', 0)->innertext; $tags = $linkInform->find('meta[name="keywords"]', 0); $description = $linkInform->find('meta[name="description"]', 0); $image = $linkInform->find('meta[property="og:image"]', 0); $icon = $linkInform->find('link[rel*="shortcut"]', 0); if (!empty($image)) { $data['image'] = $image->content; } if (!empty($icon)) { $data['icon'] = $icon->href; } else { $icon = $linkInform->find('link[rel*="icon"]', 0); if (!empty($icon)) { $data['icon'] = $icon->href; } } if (!empty($tags)) { $data['tags'] = str_limit($tags->content, $limit = 70, $end = '...'); } elseif (!empty($description)) { $data['tags'] = $description->content; } else { $data['tags'] = ''; } $data['url'] = Helper::url($link['link']); if (Link::firstOrCreate($data)) { echo 'true'; } else { echo 'false'; } }
public function addLink(Request $request) { $link = $request->all(); $this->validate($request, ['link' => 'required|url']); try { $linkInform = file_get_html($link['link']); $data['link'] = $link['link']; $data['user_id'] = $link['id']; $data['title'] = $linkInform->find('title', 0)->innertext; $tags = $linkInform->find('meta[name="keywords"]', 0); $description = $linkInform->find('meta[name="description"]', 0); $image = $linkInform->find('meta[property="og:image"]', 0); $icon = $linkInform->find('link[rel*="shortcut"]', 0); if (!empty($image)) { $data['image'] = $image->content; } if (!empty($icon)) { $data['icon'] = $icon->href; } else { $icon = $linkInform->find('link[rel*="icon"]', 0); if (!empty($icon)) { $data['icon'] = $icon->href; } } if (!empty($tags)) { $data['tags'] = str_limit($tags->content, $limit = 70, $end = '...'); } elseif (!empty($description)) { $data['tags'] = $description->content; } else { $data['tags'] = ''; } $data['url'] = Helper::url($link['link']); if ($link = Link::firstOrCreate($data)) { return response()->json(['status' => 'success', 'link' => $link]); } else { throw new Exception('Error'); } } catch (Exception $e) { return response()->json(['status' => 'false', 'message' => $e->getMessage()]); } }
public function store() { $url = Input::get('url'); $link = Link::firstOrCreate(['url' => $url]); return view('links.success', compact('link')); }