Laravel does not return variable passed by with

Asked

Viewed 82 times

-1

Hello guys beauty? Why Laravel is not resuming the object in the view. Searching for the session I can get the data.

/* ProdutoController */

public function deleta($id){
    $prod = Produto::find($id);
    $prod->delete();
    return redirect()->action('ProdutoController@lista')
        ->with('message2','deletado');
}

View

@if(!empty($message2))
    Deletado com sucesso
@endif

2 answers

0

You are using the with the wrong way, according to the documentation, try this way:

$deleted = $prod->delete();

return redirect()->action('ProdutoController@lista', ['deleted' => $deleted]);

and in the view:

@if ($deleted)
    Removido com sucesso.
@endif

You can take a look in this answer and following some tips that I myself recommended, one of them is to use English as the base language.

0

return redirect()->action('UserController@profile', ['id' => 1]);

Test like this. Using this structure.

Browser other questions tagged

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