예제 #1
0
 public function create(Request $request)
 {
     $url = $request->get('url');
     $validator = Validator::make($request->all(), ['url' => 'active_url|unique:urls|required']);
     if ($validator->fails()) {
         return json_encode(['error' => 'There was a problem with your input. Maybe this URL is already used..']);
     }
     $short = new URL();
     $alt = str_random(7);
     $count_alt = str_random(7);
     $short->create(['url' => $url, 'alt' => $alt, 'count_alt' => $count_alt]);
     return json_encode(['url' => 'https://larahh.xyz/u/' . $alt, 'counter' => 'https://larahh.xyz/c/' . $count_alt]);
 }
예제 #2
0
 public function create(Request $request)
 {
     $url = $request->get('url');
     $fails = $this->validate($request, ['url' => 'active_url|unique:urls|required']);
     if ($fails) {
         return response()->json(['errors' => $fails], 422);
     }
     $short = new URL();
     $alt = str_random(7);
     $count_alt = str_random(7);
     $short->create(['url' => $url, 'alt' => $alt, 'count_alt' => $count_alt]);
     return response()->json(['url' => 'https://larahh.xyz/u/' . $alt, 'counter' => 'https://larahh.xyz/c/' . $count_alt], 200);
 }