Display the input id data?

Asked

Viewed 66 times

1

I have the method responsible for calling a page (View) which displays the data referring to the last id entered in the database and I am using the framework Laravel and ORM Eloquent

public function exibe(Request $id)
{
    $dados = Denuncia::all()->sortByDesc('id')->first();
    return view('DenunciaView.exibeDenuncia'['dados'=>$dados]);   
}

However, I need to display the data referring to the inserted id, not necessarily the last one. For example, if the id entered was 1, the data displayed on the page (View) refer to this id, and if another id is inserted, the displayed data refers to that other id.

However, if I update the page (View) where the id data are being shown 1, the data is updated and the data of the last inserted id is displayed.

I’ve tried the method find, clause where but I was unsuccessful.

  • How are you calling this method on the route? Note: You are using the wrong ORM, bringing the data mass to then take only the first one, do this first and the code of the Eloquent without charge for the rest.

  • Hello Virgilio, I thank you for your comment regarding the use of eloquent. I’m calling the method this way: Route::get('exibeInformacaDenunciacia','Admindenunciacontroller Informacoescontroller@mostra')->name('exibeInformacaoDenunciacia');

  • Cade the id at that url?

  • because eh, when I pass the id I get this message Missing required Parameters for [Route: exibeInformacaoDenuncia] [URI: controledenuncia/exibeInformacaoDenuncia/{id}].

1 answer

0


There are several problems in your code, but I will propose a usual and correct example:

Route::get('exibeInformacaoDenuncia/{id}',
           'AdminDenunciaController\InformacoesController@exibe')
     ->name('exibeInformacaoDenuncia');

and in its method:

public function exibe($id)
{
    $dados = Denuncia::find($id);
    return view('DenunciaView.exibeDenuncia', ['dados'=> $dados]);   
}

this works is just pass correctly on your route and address the id valid and existing that will work, I did not get in the part of filtering this value or criticize if it is coming correct I will leave for you.

Reference: Routing - Laravel

  • I tested this way, the more the problem continues Missing required Parameters for [Route: exibeInformacaoDenuncia] [URI: controledenuncia/exibeInformacaoDenuncia/{id}].

  • opa my dear, it worked after I cleaned the history, very obg, I will focus now on the value filter

Browser other questions tagged

You are not signed in. Login or sign up in order to post.