Laravel collection stays empty on edit

Viewed 23

Hello i have to simulair edit functions in laravel

public function edit(FieldOfStudy $fieldOfStudy)
    {
        return view(self::VIEW_FOLDER . 'edit', [
            'item' => $fieldOfStudy,
        ]);
    }

and

 public function edit(Exercise $exercise)
    {
        return view(self::VIEW_FOLDER . 'edit', [
            'item' => $exercise,
            'talents' => Talent::orderBy('name')->pluck('id', 'name')->all(),
        ]);
    }

the first one returns no data but the second one does

First one

^ App\Models\FieldOfStudy {#2085 ▼
  #connection: null
  #table: "field_of_studies"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  +preventsLazyLoading: false
  #perPage: 15
  +exists: false
  +wasRecentlyCreated: false
  #escapeWhenCastingToString: false
  #attributes: []
  #original: []
  #changes: []
  #casts: []
  #classCastCache: []
  #attributeCastCache: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #fillable: array:2 [▶]
  #guarded: array:1 [▶]
}

Second one

App\Models\Exercise {#2067 ▼
      #connection: "mysql"
      #table: "exercises"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      +preventsLazyLoading: false
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #escapeWhenCastingToString: false
      #attributes: array:9 [▼
        "id" => 9
        "talent_id" => 3
        "type" => 4
        "week" => 1
        "content" => """
          <p>Je hebt aangegeven je verder te willen ontwikkelen op het gebied van 'analyseren'. 
    Jouw TalentCoach gaat je de komende weken daarbij helpen en ondersteunen.  ▶
          <p>&nbsp;</p>
          """
        "theme" => "Waar wil jij aan gaan werken? "
        "created_at" => "2017-12-01 13:03:45"
        "updated_at" => "2022-02-09 14:22:11"
        "excerpt" => "Van twijfelaar naar doorpakker. Effectief en efficient gedrag op basis van 
    analyse."
      ]
      #original: array:9 [▶]
      #changes: []
      #casts: []
      #classCastCache: []
      #attributeCastCache: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: []
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: array:6 [▶]
      #guarded: array:1 [▶]
    }

the routes are als both recources

Route::resource('fieldofstudies', 'AdminFieldOfStudiesController')->except('show');
Route::resource('exercises', 'AdminExercisesController')->except('show');

Why is one empty and one full? If you need more data let me know. Thanks in advance. Both off the routes have data in the database with the id Laravel 8.

1 Answers

You need to stud_case the resource:

Route::resource('field_of_studies', 'AdminFieldOfStudiesController')->except('show');

Related