Search code examples
phplaravelfrontendbackendlaravel-blade

Table stops rendering when moving the blade.php file


I got a blade.php table that renders from a index method of a controller with a @foreach method, I need to move this file in a subdirectory folder to work around some url directions on the controller, but when I move the file it stops rendering properly the data.

pic of the table when the file is not move

actual folder structure

when I made the change the table stops rendering and only renders the array operator

<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>

structure of the folders when I do the change

table when I do the change

I'm currently working with the index and the stores methods of the controller

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');

    }

I tried reverting the changes on the file directory and changed the end of the store method to try and redirect to it

]);
        if (!$nf) {
            $data = [
                'message' => 'Error al crear la familia',
                'status' => 500
            ];
            return response()->json($data, 500);
        }

        return redirect()->route('/familyNucleous');

    }

but after this I only post the new data I get that the view wasn't found


Solution

  • you moved familyNucleous.blade.php (a blade template file), into a index.php (a php file).

    Of course this file now renders as a php file and any blade specific syntax is not recognised and rendered as just text.

    You need to rename your view as index.blade.php