fadlyshafa

Untitled

Oct 22nd, 2020
118
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6.  
  7. use App\Models\Links;
  8.  
  9. class Url_controller extends Controller
  10. {
  11.     public function generate(Request $request){
  12.         $url = $request->url;
  13.  
  14.         $data = new Links;
  15.         $data->kode = rand();
  16.         $data->href = $url;
  17.         $data->save();
  18.  
  19.         $new_url = url('/').'/'.$data->kode;
  20.  
  21.         \Session::flash('url',$new_url);
  22.  
  23.         return redirect()->back();
  24.     }
  25.  
  26.     public function akses_url($kode){
  27.         $dt = Links::where('kode',$kode)->first();
  28.         $url = $dt->href;
  29.  
  30.         return redirect($url);
  31.     }
  32. }
  33.  
RAW Paste Data