skip to Main Content

i am creating a laravel crud with pivot tables. but whenever i press on edit i get this error:

Attempt to read property "name" on bool

on the ‘option’ line.

i have multiple subfolders i want to be able to select from.

<div class="form-group">
    <label for="name">{{('Subfolder')}}</label>
    <select name="subfolders" class="form-control">
        @foreach($subfolders as $subfolder)
        <option value="{{$subfolder->name}}"></option>
        @endforeach
    </select>
</div>

controller:

$files = File::all();
$fileEdit = File::find($id);
$languages = Language::all();
$tags = Tag::all();
$subfolders = Subfolder::all();
 
$users = User::all();
$roles = Role::all();
$file_subfolder = File_Subfolder::all();
//  dd($subfolders);
return view('admin.file.index', 
            compact('files', 'fileEdit', 'languages', 'tags', 
                    'subfolders' ,'users', 'roles', 'file_subfolder')
    );
}

my subfolders DD request:

 IlluminateDatabaseEloquentCollection {#1603 ▼
#items: array:5 [▼
0 => AppModelsSubfolder {#1605 ▶}
1 => AppModelsSubfolder {#1606 ▼
  #connection: "mysql"
  #table: "subfolder"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  +preventsLazyLoading: false
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #escapeWhenCastingToString: false
  #attributes: array:5 [▼
    "id" => 2
    "name" => "indoor"
    "slug" => null
    "created_at" => null
    "updated_at" => null
  ]
  #original: array:5 [▶]
  #changes: []
  #casts: []
  #classCastCache: []
  #attributeCastCache: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #fillable: array:1 [▶]
  #guarded: array:1 [▶]
}
2 => AppModelsSubfolder {#1607 ▶}
3 => AppModelsSubfolder {#1608 ▶}
4 => AppModelsSubfolder {#1609 ▶}
]
#escapeWhenCastingToString: false

if i need to add more information i will gladly do so!

2

Answers


  1. Chosen as BEST ANSWER

    i fixed the error by re nameing the $subfolders as it was already used for something else


  2. try to change the section like below.

    <div class="form-group">
        <label for="name">{{('Subfolder')}}</label>
        <select name="subfolders" class="form-control">
            @foreach($subfolders as $folder)
            <option value="{{$folder->id}}">{{ $folder->name }}</option>
            @endforeach
        </select>
    </div>```
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search