简体   繁体   中英

Laravel 8 blade File not rendering but shows when I view page source

This is my show method

public function show($id){ $student = Student::find($id);

    return view('students.student-detail', ['student' => $student]);
    
}

Routes

Route::get('/', [LoginController::class, 'index']);


/* Dashboard routes */
Route::get('/dashboard',    [DashboardController::class, 'index']);
Route::get('/student-info', [StudentController::class,   'dashboard']);
Route::get('/parent-info',  [ParentController::class,    'dashboard']);
Route::get('/teacher-info', [TeacherController::class,   'dashboard']);


/* Student routes */
Route::get( '/students', [StudentController::class, 'index']);
//Route::get( '/student-detail/{id}', [StudentController::class, 'studentDetail']);
Route::get( '/student-detail/{id}', [StudentController::class, 'show']);
Route::get( '/admit',  [StudentController::class, 'create']);
Route::post('/admit', [StudentController::class, 'store']);
Route::get('/admit/edit/{id}', [StudentController::class, 'edit']);


Blade View
@extends('layouts.app')
@section('content')
        <div class="dashboard-content-one">
            <!-- Breadcubs Area Start Here -->
            <div class="breadcrumbs-area">
                <h3>Students</h3>
                <ul>
                    <li>
                        <a href="index.html">Home</a>
                    </li>
                    <li>Student Details</li>
                </ul>
            </div>
            <!-- Breadcubs Area End Here -->
            <!-- Student Details Area Start Here -->
            <div class="card height-auto">
                <div class="card-body" style="margin-top: -1.5rem;">
                    <div class="heading-layout1">
                        <div class="item-title">
                            <h3>About Me</h3>
                        </div>
                       <div class="dropdown">
                            <a class="dropdown-toggle" href="#" role="button"
                            data-toggle="dropdown" aria-expanded="false">...</a>

                            <div class="dropdown-menu dropdown-menu-right">
                                <a class="dropdown-item" href="#"><i class="fas fa-eye text-orange-red"></i> View</a>
                                <a class="dropdown-item" href="admit/edit/"><i class="fas fa-cogs text-dark-pastel-green"></i> Update</a>
                                <a class="dropdown-item" href="#"><i class="fas fa-times text-orange-peel"></i> Suspend</a> </a>
                            </div>
                        </div>
                    </div>
                    <div class="single-info-details">
                        <div class="item-img">
                            <img src="img/figure/student1.jpg" alt="student">
                        </div>
                        <div class="item-content">
                            <div class="header-inline item-header">
                                <h3 class="text-dark-medium font-medium">{{$student->first_name . " " . $student->last_name}}</h3>
                                <div class="header-elements">
                                    <ul>
                                        <li><a href="#"><i class="far fa-edit"></i></a></li>
                                        <li><a href="#"><i class="fas fa-print"></i></a></li>
                                        <li><a href="#"><i class="fas fa-download"></i></a></li>
                                    </ul>
                                </div>
                            </div>
                            <p>{{ $student->bio }}</p>
                            <div class="info-table table-responsive">
                                <table class="table text-nowrap">
                                    <tbody>
                                        <tr>
                                            <td>Name:</td>
                                            <td class="font-medium text-dark-medium">{{$student->first_name . " " . $student->last_name}}</td>
                                        </tr>
                                        <tr>
                                            <td>Gender:</td>
                                            <td class="font-medium text-dark-medium">{{$student->gender->name}}</td>
                                        </tr>
                                        <tr>
                                            <td>Father Name:</td>
                                            <td class="font-medium text-dark-medium">{{ $student->parents->first_name . " " . $student->parents->last_name }}</td>
                                        </tr>
                                        <tr>
                                            <td>Mother Name:</td>
                                            <td class="font-medium text-dark-medium">{{ $student->parents->spouse_first_name . " " . $student->parents->spouse_last_name }}</td>
                                        </tr>
                                        <tr>
                                            <td>Date Of Birth:</td>
                                            <td class="font-medium text-dark-medium">{{$student->dob}}</td>
                                        </tr>
                                        <tr>
                                            <td>Religion:</td>
                                            <td class="font-medium text-dark-medium">{{$student->religion->name}}</td>
                                        </tr>
                                        <tr>
                                            <td>Father Occupation:</td>
                                            <td class="font-medium text-dark-medium">{{$student->parents->occupation}}</td>}</td>
                                        </tr>
                                        <tr>
                                            <td>E-mail:</td>
                                            <td class="font-medium text-dark-medium">{{$student->email}}</td>
                                        </tr>
                                        <tr>
                                            <td>Admission Date:</td>
                                            <td class="font-medium text-dark-medium">{{$student->created_at}}</td>
                                        </tr>
                                        <tr>
                                            <td>Class:</td>
                                            <td class="font-medium text-dark-medium">{{$student->classes->name}}</td>
                                        </tr>
                                        <tr>
                                            <td>Section:</td>
                                            <td class="font-medium text-dark-medium">{{$student->section->name}}</td>
                                        </tr>
                                        <tr>
                                            <td>Roll:</td>
                                            <td class="font-medium text-dark-medium">{{$student->admission_id}}</td></td>
                                        </tr>
                                        <tr>
                                            <td>Address:</td>
                                            <td class="font-medium text-dark-medium">{{ $student->home_address }},{{$student->lga->name}},{{$student->state->name}} State</td>
                                        </tr>
                                        <tr>
                                            <td>Phone:</td>
                                            <td class="font-medium text-dark-medium">{{$student->phone}}</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Student Details Area End Here -->
@endsection

I am passing the data from the student to the show method. when I dd($students) it returns data for students/student-detail/1 etc

but when I take out the dump and reload, it comes up blank.

so I decided to check if the data is coming to the view at all by viewing page source. When I do this, I see the results in the respective html elements as desired but it just wouldn't render.

Please can anyone help?

What caused the blank screen was a plain declaration of javascript files in the footer. I was meant to use laravel assets to include project dependencies. like; scr = "{{assets('/js/another_directory/file.js')}}".

Once I did that, the page rendered.

Try this

public function show($id){ 
    $student = Student::find($id)->first();
    return view('students.student-detail', ['student' => $student]);
    
}
public function show($id){ 
    $student = Student::find($id)->first();
    return view('students.student-detail',compact('student')); 
}

for reference visit this url: https://www.geeksforgeeks.org/different-ways-for-passing-data-to-view-in-laravel/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM