我的控制器有问题并在其中获取数据。我的问题是,当我像这样让我的团队时:
$team = Team::where('join_number', '=', $data['team'])->get();
我似乎无法通过去访问它
$team->join_request_needed = 'True'
例如?如果我只是死转储
$team->join_request_needed
我收到“此集合实例上不存在属性 [join_request_needed]”。我如何访问这些数据?如果我死了转储$team,我会得到这个;所以它得到数据?
Illuminate\Database\Eloquent\Collection {#282 ▼
#items: array:1 [▼
0 => App\Team {#291 ▼
#guarded: []
#connection: "sqlite"
#table: "teams"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:8 [▶]
#original: array:8 [▼
"id" => "1"
"user_id" => "1"
"name" => "team1"
"description" => null
"join_request_needed" => "0"
"join_number" => "1574832472024"
"created_at" => "2019-11-27 05:27:52"
"updated_at" => "2019-11-27 22:46:55"
]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
}
]
}
这是我的整个功能(到目前为止只是粗略,因为我坚持获取数据):
public function check() {
$data = request()->validate([
'email' => ['required', 'email'],
'team' => ['required', 'alpha_num', 'exists:teams,join_number']
]);
繁星coding
繁花不似锦