Property [id] does not exist in Laravel 5.5

Saiful Azam

Why i am keep getting this error: Property [id] does not exist on this collection instance.

My method:

public function modes()
{
    $modes = Genre::limit($this->limit)->get();


    return new GenresResource($modes);
}

My Resource

public function toArray($request)
{
    return [
        'id' => $this->id,
        'name' => $this->name
    ];
}

M Model

class Genre extends Model {

/**
 * The database table used by the model.
 *
 * @var string
 */
protected $table = 'genres';

protected $guarded = ['id'];

}

Dwight

You'll want to change your controller method to indicate that it's receiving a collection, not a single model.

$modes = Genre::limit($this->limit)->get();

return GenresResource::collect($modes);

Generally you'll want to give your resource a singular name so you may want to consider calling it GenreResource too.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

laravel5: does not exist on this collection instance

Laravel 5 Class admin does not exist

Defined controller does not exist in Laravel 5

Method [header] does not exist on view - Laravel 5

Angular 5: error thrown after `ng serve --prod` only "Property 'id' does not exist on type..."

Property [id] does not exist on this collection instance in laravel 5.5

laravel collection/format printing |Property [id] does not exist on this collection instance

Property [id] does not exist on this collection instance - Laravel 6

Angular 5 to 6 Upgrade: Property 'map' does not exist on type Observable

Angular 5 - Error on template: "Property 'length' does not exist on type 'AbstractControl'"

Angular 5 build error "Property does not exist on type"

Angular 5 : Property 'then' does not exist on type 'Observable<any>'

Angular 5: Property 'description' does not exist on type 'any[]'

Angular 5 - Property 'subscribe' does not exist on type '() => Observable<any>'

Angular 5 Property 'username' does not exist on type 'string[]'

Laravel 5 (custom) method for calculating age(in days) does not exist

Laravel 5 - artisan seed [ReflectionException] Class SongsTableSeeder does not exist

Laravel 5 returns blank page for a method which does not exist

Laravel 5 File Uploading getClientOriginalExtention does not exist error

Class App\Http\Controllers\StudentController does not exist in Laravel 5

MVC 5 does a controller exist

Property id does not exist on type string

Property [id] does not exist on this collection instance

Property 'id' does not exist on type 'object'?

Property 'id' does not exist on type 'typeof Foods'

Property id does not exist on type 'never'

Property [id] does not exist on the Eloquent builder instance

Property 'id' does not exist on type 'any[]'

Property 'id' does not exist on type 'never'. typescript