How to not pass the ID of an element by the laravel URL

0

This is my route

Route :: get ('companies / delete / {notice}', 'CompanyController @ delete');

this is the button action

This is my role in controlling

What happens if I pass this url right into the browser localhost: 8000 / businesses / delete / 1 it deletes directly has how to send the id of a particular record without being the way I am using the button and hiding in the user's view so he does not know which ID is what he is passing into the backEnd since I am working with a system where several clients can register several companies and this one way another customer can exclude another company understands that it is not related to itself properly

    
asked by anonymous 23.08.2018 / 02:42

1 answer

0

I made a slightly different example of a simple way to delete a given data from a table.

In the Controller I did

<?php

 namespace App\Http\Controllers;

 use App\Empresa;
 use Illuminate\Http\Request;

 class EmpresaController extends Controller
 {
  private $empresa;
  public function __construct(Empresa $empresa)
  {
    $this->empresa=$empresa;
  }

  public function index() {
     $empresas = $this->empresa->all();
     return view('welcome', compact("empresas"));
  }

  public function deletar($id) {
    $empresaDeletar = $this->empresa->find($id);
    $empresaDeletar->delete();

    $empresas = $this->empresa->all();
    return view('welcome', compact("empresas"));
}
}

In the web.php file I did:

<?php

 Route::get('/', 'EmpresaController@index');
 Route::get('/empresa/{id}/deletar', 'EmpresaController@deletar')- 
 >name('empresa.deletar');

Finally I did an example in a view, I did just just to exemplify but it would be ideal to have a table in the view.

<h1>Deletanto empresas</h1>

@foreach($empresas as $empresa)
    <p> {{$empresa->nome}} " - "
    Ação <a href="{{route('empresa.deletar',$empresa->id)}}">Deletar</a>
   </br>
@endforeach
    
26.08.2018 / 21:00