Reputation: 113
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:
When I click edit button, no data is not fetch in the form like this:
and I check the URL, it is correct:
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:
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:
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?
Upvotes: 0
Views: 859
Reputation: 2023
Your route looks incorrect.
Try this instead:
Route::resource('student-applications', 'StudentApplicationController', ['except' => ['show']]);
Upvotes: 1