How to hide the url in laravel when you use get to edit?

3

I want to edit a record using its id and I have the following code in my view:

<a href="{{route('guest.edit',$g->id)}}" class="btn btn-simple btn-warning btn-icon edit"><i class="ti-pencil-alt"></i></a>

And so I have on my route:

Route::resource('guest','GuestController');

Then on my controller:

public function edit($id){
    $guest=Guest::find($id);
    return view('Guests.edit1',compact('guest'));
}

The problem with this is that the id appears on my route, which I think is not safe, appears like this

http://localhost:8081/guest/2/edit

How do I fix it in such a way that the id is not shown in the url, or the url is not displayed at all

    
asked by lucho 08.11.2017 в 20:29
source

4 answers

4

A possible solution would be to use Encryption to display its encrypted parameter. From the view, I would use encrypt from blade

<a href="{{route('guest.edit',Crypt::encrypt($g->id))}}"

Then in the controller decrypt this value.

public function edit($id){
  $id =  Crypt::decrypt($id);
  $guest=Guest::find($id);
  return view('Guests.edit1',compact('guest'));
}

Do not forget use Illuminate\Support\Facades\Crypt;

    
answered by 08.11.2017 / 21:03
source
2

I found the best solution to the problem using FakeID .

Masks all the ids of your model, simply by placing the namespace and the trait , it will hide your id and it will generate a very clean URL, example, if you have something like this:

localhost/2/editar

I'll change it for something like this:

Localhost/97302855/editar

You do not have to worry about encrypting or decrypting , it does everything automatically.

  

link

    
answered by 30.07.2018 в 23:33
1

You could also try it with the use of friendly urls, you have a cleaner url and you manage to hide the id.

I use this package link allows you to generate friendly url in a simple way.

    
answered by 31.07.2018 в 22:50
0

Try it this way with an alias on the route:

Route::get('/url/{id}',[
   'uses'=>'Controller@metodo',
    'as'=>'registration'
]);

or also with this laravel helper:

Hash::make($id)
    
answered by 08.11.2017 в 20:45