Laravel - 某些 table 无法获取数据

Laravel - Data is not Fetch for some table

我尝试在表单中显示数据。某些 table 已成功获取,但某些 table 未成功获取。我尝试 'dd' 结果发现连接和 table 名称不存在。

但它可以像这样获取整个 table:

当我点击编辑按钮时,没有数据不是以这样的形式获取的:

我检查了 URL,它是正确的:

我的控制器:

public function edit(StudentApplication $student_applications)
{
    dd($student_applications);
    return view('student_application.edit', compact('student_applications'));
}

我的模特:

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class StudentApplication extends Model

{
use Notifiable;

 /**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'name', 'email'
];

/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
protected $hidden = [
    'password', 'remember_token',
];

/**
 * The attributes that should be cast to native types.
 *
 * @var array
 */
protected $casts = [
    'email_verified_at' => 'datetime',
];

}

我的看法

<label class="form-control-label" for="student_name">{{ __('Student Name') }}</label>
<input type="text" name="student_name" id="student_name" class="form-control{{ $errors->has('student_name') ? ' is-invalid' : '' }}" placeholder="{{ __('Student Name') }}" value="{{ old('student_name', $student_applications->student_name) }}"  required>

我的dd结果:

可以看到连接,table和属性都是空的,没有数据。

我用其他模块做了完全相同的代码,它是这样工作的:

我的迁移:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateStudentApplicationsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('student_applications', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('student_name');
            $table->bigInteger('student_ic_number');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('address');
            $table->string('guardian_name');
            $table->string('guardian_ic_number');
            $table->string('phone_number');
            $table->string('relationship');
            $table->rememberToken();
            $table->timestamps();
        });
    }

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::dropIfExists('student_applications');
}

}

我的路线: 我在这里放了两条路线,用户路线像我在上图中显示的那样工作,当我尝试编辑时,学生申请路线不工作。

Route::resource('user', 'UserController', ['except' => ['show']]);
Route::resource('studentapplication', 'StudentApplicationController', ['except' => ['show']]);

你们有解决我的问题的方法吗?

您的路线看起来不正确。

试试这个:

Route::resource('student-applications', 'StudentApplicationController', ['except' => ['show']]);