You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

提交Feedback编辑返回Show页面,详情表格不显示的问题求助

问题:提交Feedback编辑表单后,案件详情表格消失,仅显示成功提示

提交Feedback的编辑表单并重定向回Show页面后,页面只显示成功提示消息,原本的案件详情表格无法显示:

  • 操作前:页面展示完整的案件详情表格,包含用户信息、反馈内容、状态编辑表单等
  • 提交后:仅显示成功提示框,表格内容完全不显示

控制器代码(FeedbackController)

public function show(Feedback $feedback){
    $feedback->load('user');
    return view('feedback.show',compact('feedback'));
}

public function update(Request $request, Feedback $feedback){
    $request->validate([
        'status' => 'required|not_in:0',
        'remark' => ['string', 'max:255', 'nullable']
    ]);

    $feedback->fill($request->post())->save();
    return redirect()->back()->with('success','Feedback updated successfully');
}

Blade视图代码(feedback/show.blade.php)

@if (session('success'))
    <div class="alert alert-success" role="alert">
        <button type="button" class="close" data-dismiss="alert">×</button>
        {{ session('success') }}
    </div>
@else
    <h2><a href="{{ route('feedback.index') }}" style="color: black"><i class="fa fa-arrow-left" aria-hidden="true"></i></a> Case ID - {{ $feedback->id }}</h2>
    <div class="table-responsive-lg  pt-4">
        <table class="table table-active table-borderless table-hover" style="width:100%;border-radius: 5px">
            <tr>
                <th scope="col" style="width:10%">Name</th>
                <td>{{ $feedback->user->name }}</td>
            </tr>
            <tr>
                <th scope="col" style="width:10%">Title</th>
                <td>{{ $feedback->title }}</td>
            </tr>
            <tr>
                <th scope="col" style="width:10%">Message</th>
                <td>{{ $feedback->details }}</td>
            </tr>
            <tr>
                <th scope="col" style="width:10%">Created at</th>
                <td>{{ $feedback->created_at }}</td>
            </tr>
            <tr>
                <th scope="col" style="width:10%">Reply</th>
                <td><a href="mailto:{{ $feedback->user->email }}" class="btn btn-primary" style="color: white">Email</a></td>
            </tr>
            <tr>
                <form action="{{ route('feedback.update',$feedback->id) }}" method="post">
                    @csrf
                    @method('PUT')
                    <th scope="col" style="width:10%">Status</th>
                    <td>
                        <select name="status" class="custom-select @error('status') is-invalid @enderror">
                            <option @if(( old('status') ?? $feedback->status)==NULL)selected
                                @endif value="0">Choose...</option>
                            <option @if(( old('status') ?? $feedback->status)==1)selected
                                    @endif value="1">Received</option>
                            <option @if(( old('status') ?? $feedback->status)==2)selected
                                    @endif value="2">Reply</option>
                        </select>
                        @error('status')
                            <span class="invalid-feedback" role="alert">
                                <strong>{{ $message }}</strong>
                            </span>
                        @enderror
                    </td>
            </tr>
            <tr>
                <th scope="col" style="width:10%">Remark</th>
                <td>
                    <textarea name="remark" class="form-control @error('remark') is-invalid @enderror" placeholder="Write your remark here" rows="4">{{ old('remark') ?? $feedback->remark }}</textarea>
                    @error('remark')
                    <span class="invalid-feedback" role="alert">
                                <strong>{{ $message }}</strong>
                            </span>
                    @enderror
                </td>
            </tr>
            <tr>
                <th scope="col" style="width:10%"></th>
                <td style="text-align: right;width:100%">
                    <button type="submit" class="btn btn-primary">Save</button>
                    </form>
                </td>
            </tr>
            <tbody>
            </tbody>
        </table>

解决方案

核心问题

视图中使用了@if (session('success')) ... @else ...的排他逻辑,导致存在成功提示时,完全跳过表格内容的渲染。

修改步骤

  1. 调整视图逻辑:移除@else,让成功提示和表格内容同时渲染:
{{-- 成功提示存在时显示 --}}
@if (session('success'))
    <div class="alert alert-success" role="alert">
        <button type="button" class="close" data-dismiss="alert">×</button>
        {{ session('success') }}
    </div>
@endif

{{-- 表格内容始终渲染 --}}
<h2><a href="{{ route('feedback.index') }}" style="color: black"><i class="fa fa-arrow-left" aria-hidden="true"></i></a> Case ID - {{ $feedback->id }}</h2>
<div class="table-responsive-lg  pt-4">
    <table class="table table-active table-borderless table-hover" style="width:100%;border-radius: 5px">
        <tr>
            <th scope="col" style="width:10%">Name</th>
            <td>{{ $feedback->user->name }}</td>
        </tr>
        <tr>
            <th scope="col" style="width:10%">Title</th>
            <td>{{ $feedback->title }}</td>
        </tr>
        <tr>
            <th scope="col" style="width:10%">Message</th>
            <td>{{ $feedback->details }}</td>
        </tr>
        <tr>
            <th scope="col" style="width:10%">Created at</th>
            <td>{{ $feedback->created_at }}</td>
        </tr>
        <tr>
            <th scope="col" style="width:10%">Reply</th>
            <td><a href="mailto:{{ $feedback->user->email }}" class="btn btn-primary" style="color: white">Email</a></td>
        </tr>
        <tr>
            <form action="{{ route('feedback.update',$feedback->id) }}" method="post">
                @csrf
                @method('PUT')
                <th scope="col" style="width:10%">Status</th>
                <td>
                    <select name="status" class="custom-select @error('status') is-invalid @enderror">
                        <option @if(( old('status') ?? $feedback->status)==NULL)selected
                            @endif value="0">Choose...</option>
                        <option @if(( old('status') ?? $feedback->status)==1)selected
                                @endif value="1">Received</option>
                        <option @if(( old('status') ?? $feedback->status)==2)selected
                                @endif value="2">Reply</option>
                    </select>
                    @error('status')
                        <span class="invalid-feedback" role="alert">
                            <strong>{{ $message }}</strong>
                        </span>
                    @enderror
                </td>
        </tr>
        <tr>
            <th scope="col" style="width:10%">Remark</th>
            <td>
                <textarea name="remark" class="form-control @error('remark') is-invalid @enderror" placeholder="Write your remark here" rows="4">{{ old('remark') ?? $feedback->remark }}</textarea>
                @error('remark')
                <span class="invalid-feedback" role="alert">
                            <strong>{{ $message }}</strong>
                        </span>
                @enderror
            </td>
        </tr>
        <tr>
            <th scope="col" style="width:10%"></th>
            <td style="text-align: right;width:100%">
                <button type="submit" class="btn btn-primary">Save</button>
                </form>
            </td>
        </tr>
        <tbody>
        </tbody>
    </table>
  1. 优化控制器重定向:将redirect()->back()改为明确的路由跳转,避免潜在的路由歧义:
public function update(Request $request, Feedback $feedback){
    $request->validate([
        'status' => 'required|not_in:0',
        'remark' => ['string', 'max:255', 'nullable']
    ]);

    $feedback->fill($request->post())->save();
    return redirect()->route('feedback.show', $feedback)->with('success','Feedback updated successfully');
}

内容的提问来源于stack exchange,提问作者p1ai

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 16:05:25