我找不到原因......但我无法获得我的 var 和任何其他. 函数实际上保存数据并验证正常,然后也将新数据发送回编辑视图,但我无法访问我的 $success 变量...CourseController@update:class CourseController extends Controller { public function update( Request $request, Course $course ) { // Validates data or return to view with errors $request->validate( Course::$validation_rules ); // Pass: Gets the record from db or returns 404 $course = Course::findOrFail( $course->id ); // Update the course $course->name = Str::ucfirst( $request->name ); $course->description = Str::ucfirst( $request->description ); // Save the data $course->save(); // Redirect to view with success return redirect()->route( 'courses.edit', $course ) ->with( 'success', 'Cambios guardados.' ) // problem here? where? ; }}Course (model):class Course extends Model { public static $validation_rules = [ 'name' => 'required', 'description' => 'required' ];}edit.blade.php (portion):{{-- some code before --}} @if ( $errors->any() ) @foreach ( $errors->all() as $error ) <div class="alert alert-danger alert-dismissible fade show" role="alert"> <strong class="d-block"> {{ $error }} </strong> <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> @endforeach @elseif ( $success ?? false ) <div class="alert alert-success alert-dismissible fade show" role="alert"> <strong>{{ $success }}</strong> <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> @endif{{-- some code after --}}这就是我目前所拥有的。这非常奇怪,我总是从中得到 null$success以及我尝试的任何其他......
1 回答
慕桂英4014372
TA贡献1871条经验 获得超13个赞
当您使用重定向时,您的$success
变量会在会话中闪烁with
。
在您应该使用的视图文件中
@elseif (session('success'))
- 1 回答
- 0 关注
- 97 浏览
添加回答
举报
0/150
提交
取消