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 >
<label for="name">{{('Subfolder')}}</label>
<select name="subfolders" >
@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:
Illuminate\Database\Eloquent\Collection {#1603 ▼
#items: array:5 [▼
0 => App\Models\Subfolder {#1605 ▶}
1 => App\Models\Subfolder {#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 => App\Models\Subfolder {#1607 ▶}
3 => App\Models\Subfolder {#1608 ▶}
4 => App\Models\Subfolder {#1609 ▶}
]
#escapeWhenCastingToString: false
if i need to add more information i will gladly do so!
CodePudding user response:
try to change the section like below.
<div >
<label for="name">{{('Subfolder')}}</label>
<select name="subfolders" >
@foreach($subfolders as $folder)
<option value="{{$folder->id}}">{{ $folder->name }}</option>
@endforeach
</select>
</div>```
CodePudding user response:
i fixed the error by re nameing the $subfolders as it was already used for something else