0

I try to display data in a form. Some table are successfully fetch but some table is not. I try to 'dd' and it turns out the connection and table name is not there.

But it can fetch to whole table like this:

enter image description here

When I click edit button, no data is not fetch in the form like this:

enter image description here

and I check the URL, it is correct:

enter image description here

My controller:

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

My Model:

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',
];

}

My View

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

My dd result:

enter image description here

You can see that the connection, table and attributes are null and no data.

I did the exact same code with other module, and it works like this:

enter image description here

My Migration:

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

}

My Route: I put two route here, the user route is working like I show in the picture above, the studentapplication route is not working when I try to edit.

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

Do you guys have a solution for my problem?

4
  • plz post your migration about this table. Commented Apr 19, 2020 at 6:55
  • This is probably a malformed route issue since the model is not correctly passed to your controller. Can we see your route file? Commented Apr 19, 2020 at 7:00
  • @TsaiKoga I put my migration in the question Commented Apr 19, 2020 at 7:22
  • @LobsterBaz Sure, I edit the question with my route Commented Apr 19, 2020 at 7:23

1 Answer 1

1

Your route looks incorrect.

Try this instead:

Route::resource('student-applications', 'StudentApplicationController', ['except' => ['show']]);
Sign up to request clarification or add additional context in comments.

3 Comments

isn't that differences between 'studentapplication' and 'student-application' just to determine how the url will looks like?
@lililuna it's the base URI the controller handles, I don't think it's just cosmetic but I could be wrong. Did it make a difference?
When you said about the URI controller handles, I notice that I make mistake on the base URI. You are basically correct. I pass different thing from controller to view. My silly mistake. Thank you so much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.