移动blade.php文件后Laravel表格停止渲染的问题排查
问题:Blade表格移至子目录后无法渲染数据,仅显示数组符号
问题描述
原本通过控制器index方法结合@foreach语句渲染的Blade表格,为适配控制器URL规则将文件移至子目录后,表格无法正常渲染数据,仅显示数组符号。
相关截图
- 文件未移动时的表格截图:

- 修改前的文件夹结构:

- 修改后的文件夹结构:

- 修改后的表格截图:

表格Blade代码
<div class="container"> <div> <a href="{{ route('familyNucleous.create') }}">Agregar Familia</a> </div> <table class="table table-dark table-hover table-bordered table-striped"> <thead> <th>ID</th> <th>Nombre Completo</th> <th>Cedula</th> <th>Nacimiento</th> <th>Edad</th> <th>Parentesco</th> <th>Ocupacion</th> <th>Lugar de trabajo</th> <th>Ingreso/Fuente</th> <th>Padecimientos</th> <th>Total ingresos Nucleo Familiar</th> <th>Ingresos jefe de familiar</th> <th>Total Ingresos</th> </thead> <tbody> @foreach ($nf as $nfs) <tr> <td>{{ $nfs->id }}</td> <td>{{ $nfs->name }} {{ $nfs->middlename }} {{ $nfs->surname }} {{ $nfs->secondsurname }}</td> <td>{{ $nfs->identification }}</td> <td>{{ $nfs->bornyear }}</td> <td>{{ $nfs->age }}</td> <td>{{ $nfs->kinship }}</td> <td>{{ $nfs->occupation }}</td> <td>{{ $nfs->workplace }}</td> <td>{{ $nfs->income }}</td> <td>{{ $nfs->ailments }}</td> <td>{{ $nfs->totalFamilyIncome }}</td> <td>{{ $nfs->familyHeadIncome }}</td> <td>{{ $nfs->totalIncome }}</td> </tr> @endforeach </tbody> </table> </div>
当前控制器代码(index和store方法)
class nuclearFamilyController extends Controller { public function index() { $nf = NuclearFamily::all(); return view('familyNucleous.index', compact('nf')); } public function create() { return view('familyNucleous.create'); } public function store(Request $request) { $validator = Validator::make($request->all(), [ 'familyNumber' => 'required', 'name' => 'required', 'middlename' => 'nullable', 'surname' => 'required', 'secondsurname' => 'required', 'identification' => 'required', 'bornyear' => 'required', 'age' => 'required', 'kinship' => 'required', 'occupation' => 'required', 'workplace' => 'required', 'income' => 'required', 'ailments' => 'required', 'totalFamilyIncome' => 'required', 'familyHeadIncome' => 'required', 'totalIncome' => 'required', 'familyId' => 'required', 'mainCedula' => 'required' ]); if ($validator->fails()) { $data = [ 'message' => 'Erroren la validacion de los datos', 'errors' => $validator->errors(), 'status' => 400 ]; return response()->json($data, 400); } $nf = NuclearFamily::create([ 'familyNumber' => $request->familyNumber, 'name' => $request->name, 'middlename' => $request->middlename, 'surname' => $request->surname, 'secondsurname' => $request->secondsurname, 'identification' => $request->identification, 'bornyear' => $request->bornyear, 'age' => $request->age, 'kinship' => $request->kinship, 'occupation' => $request->occupation, 'workplace' => $request->workplace, 'income' => $request->income, 'ailments' => $request->ailments, 'totalFamilyIncome' => $request->totalFamilyIncome, 'familyHeadIncome' => $request->familyHeadIncome, 'totalIncome' => $request->totalIncome, 'familyId' => $request->familyId, 'mainCedula' => $request->mainCedula ]); if (!$nf) { $data = [ 'message' => 'Error al crear la familia', 'status' => 500 ]; return response()->json($data, 500); } return redirect()->route('familyNucleous.index'); } }
尝试过的解决方法及问题
曾尝试恢复文件目录并修改store方法的重定向:
]); if (!$nf) { $data = [ 'message' => 'Error al crear la familia', 'status' => 500 ]; return response()->json($data, 500); } return redirect()->route('/familyNucleous'); }
但提交新数据后出现视图未找到的错误。
内容的提问来源于stack exchange,提问作者Kuo
相关产品推荐
相关产品推荐

