when i use api resource collection in postman with type GET it returns Property [name] does not exist on this collection instance i dont know why although i wrote everything correct please help
i make a collection folder and it returns info
note : when i return $instructors = User::where('type',3)->get(); it returns informations
here is my code
my route api.php
Route::resource('instructors',InstructorController::class);
my collection file
public function toArray($request)
{
// return parent::toArray($request);
return [
'name' => $this->name,
'email' => $this->email,
'area_id' => $this->area_id,
'whatsapp' => $this->whatsapp,
'phone' => $this->phone,
'description' => $this->description,
];
}
my controller
public function index()
{
$instructors = User::where('type',3)->get();
$collection = new InstructorCollection($instructors);
return response()->json(['data'=>$collection,'error']);
}
my table
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name', 250);
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->bigInteger('area_id')->unsigned()->nullable();
$table->foreign('area_id')->references('id')->on('areas')->onDelete('set null');
$table->string('whatsapp')->nullable();
$table->string('phone')->nullable();
$table->string('facebook')->nullable();
$table->tinyInteger('type');
$table->text('description')->nullable();
$table->integer('views')->default('0');
$table->rememberToken();
$table->timestamps();
$table->softDeletes();
});
}