Guilherme Costa
Guilherme Costa

Reputation: 310

Laravel returns no variable passed by the with

Hello guys beauty? Because Laravel is not returning the object in view. Seeking 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

Upvotes: 0

Views: 33

Answers (2)

xmhafiz
xmhafiz

Reputation: 3538

you can check the session variable if exist.

@if (session()->has('message2'))
    Deletado com sucesso
@endif

Upvotes: 1

Rob Fonseca
Rob Fonseca

Reputation: 3819

The redirect with() method flashes data to the session. It does not pass the variable directly to your view. Try the following

 @if(!empty(session('message2'))
    Deletado com sucesso
@endif

Upvotes: 2

Related Questions