Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function shorten(Request $request)
- {
- $url = Validator::make($request->all(), [
- 'url' => 'url'
- ])->validate()['url'];
- $url_model = Url::firstOrNew(['url' => $url]);
- if ($success = $url_model->exists)
- // the model exists in the database .
- // we'll retrieve the shortend url and skip directly to displaying the view .
- $shortend_url = $url_model->shortend_url;
- elseif ($success = $url_model->save()) {
- // it does not exist, so we'll save it to retrieve the id assigned by the database .
- $shortend_url = env('APP_URL') . '/' . $url_model->id;
- $success = $url_model->update(compact('shortend_url'));
- }
- return view('result', compact('success', 'url', 'shortend_url'));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement