Last updated on
laravel redirect with value not working
redirect 中若使用 with 時, 它將不起作用
我在 laravel 5 和 laravel 6 都試過了 :/
後來用了 withErrors 後, 才終於有反應, 但回應的 key 始終是 $errors
所以在最初我是這樣寫的:
return redirect(‘/dashboard’)->withErrors([‘success’ => ‘The post has been created successfully’]);
@if(isset($errors))
foreach($errors->all() as $error){
{{$error}} // The post has been created successfully
}
但是明明是回 success , 結果卻始終是 error…
@error()
後來查了一下官方文件才發現有 @error
@error(‘error’)
this is error: {{ $message }}
@enderror
@error(‘success’)
this is success: {{ $message }}
@enderror
他的值都是 $message ,所以不用自己去定義