未定义的数组键“ school_name”使用Flatmap
我正在使用flatmap将键和值相关的值 但这给了我一个错误未定义的数组键“ school_name”我不知道为什么 尽管我确实返回$设置,但它给我带来了这样的
{
setting: {
current_session: "2021-2022",
school_title: "MS",
school_name: "Mora Soft International Schools",
end_first_term: "01-12-2021",
end_second_term: "01-03-2022",
phone: "0123456789",
address: "القاهرة",
school_email: "[email protected]",
logo: "1.jpg"
}
}
表,这是我的表设置表
Schema::create('settings', function (Blueprint $table) {
$table->id();
$table->string('key');
$table->string('value');
$table->timestamps();
});
,这是我的web.php路由
Route::resource('settings', 'SettingController');
,这是我的设置controller
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$collection = setting::all();
$setting['setting'] = $collection->flatMap(function ($collection){
return [$collection->key => $collection->value];
});
// return $setting;
return view('pages.settings.index',compact('setting'));
}
,这是我的刀片,可查看表单
<form enctype="multipart/form-data" method="post" action="{{route('settings.update','test')}}">
@csrf @method('PUT')
<div class="row">
<div class="col-md-6 border-right-2 border-right-blue-400">
<div class="form-group row">
<label class="col-lg-2 col-form-label font-weight-semibold">اسم المدرسة<span class="text-danger">*</span></label>
<div class="col-lg-9">
<input name="school_name" value="{{ $setting['school_name'] }}" required type="text" class="form-control" placeholder="Name of School">
</div>
</div>
<div class="form-group row">
<label for="current_session" class="col-lg-2 col-form-label font-weight-semibold">العام الحالي<span class="text-danger">*</span></label>
<div class="col-lg-9">
<select data-placeholder="Choose..." required name="current_session" id="current_session" class="select-search form-control">
<option value=""></option>
@for($y=date('Y', strtotime('- 3 years')); $y<=date('Y', strtotime('+ 1 years')); $y++)
<option {{ ($setting['current_session'] == (($y-=1).'-'.($y+=1))) ? 'selected' : '' }}>{{ ($y-=1).'-'.($y+=1) }}</option>
@endfor
</select>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label font-weight-semibold">اسم المدرسة المختصر</label>
<div class="col-lg-9">
<input name="school_title" value="{{ $setting['school_title'] }}" type="text" class="form-control" placeholder="School Acronym">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label font-weight-semibold">الهاتف</label>
<div class="col-lg-9">
<input name="phone" value="{{ $setting['phone'] }}" type="text" class="form-control" placeholder="Phone">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label font-weight-semibold">البريد الالكتروني</label>
<div class="col-lg-9">
<input name="school_email" value="{{ $setting['school_email'] }}" type="email" class="form-control" placeholder="School Email">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label font-weight-semibold">عنوان المدرسة<span class="text-danger">*</span></label>
<div class="col-lg-9">
<input required name="address" value="{{ $setting['address'] }}" type="text" class="form-control" placeholder="School Address">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label font-weight-semibold">نهاية الترم الاول </label>
<div class="col-lg-9">
<input name="end_first_term" value="{{ $setting['end_first_term'] }}" type="text" class="form-control date-pick" placeholder="Date Term Ends">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label font-weight-semibold">نهاية الترم الثاني</label>
<div class="col-lg-9">
<input name="end_second_term" value="{{ $setting['end_second_term'] }}" type="text" class="form-control date-pick" placeholder="Date Term Ends">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label font-weight-semibold">شعار المدرسة</label>
<div class="col-lg-9">
<div class="mb-3">
<img style="width: 100px" height="100px" src="{{ URL::asset('attachments/logo/'.$setting['logo']) }}" alt="">
</div>
<input name="logo" accept="image/*" type="file" class="file-input" data-show-caption="false" data-show-upload="false" data-fouc>
</div>
</div>
</div>
</div>
<hr>
<button class="btn btn-success btn-sm nextBtn btn-lg pull-right" type="submit">{{trans('Students_trans.submit')}}</button>
</form>
i am using flatMap to get the keys and the value related together
but it gives me an error Undefined array key "school_name" i dont know why
although i do return $setting it gives me like this
{
setting: {
current_session: "2021-2022",
school_title: "MS",
school_name: "Mora Soft International Schools",
end_first_term: "01-12-2021",
end_second_term: "01-03-2022",
phone: "0123456789",
address: "القاهرة",
school_email: "[email protected]",
logo: "1.jpg"
}
}
this is my table settings table
Schema::create('settings', function (Blueprint $table) {
$table->id();
$table->string('key');
$table->string('value');
$table->timestamps();
});
and this is my web.php route
Route::resource('settings', 'SettingController');
and here is my settingcontroller
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$collection = setting::all();
$setting['setting'] = $collection->flatMap(function ($collection){
return [$collection->key => $collection->value];
});
// return $setting;
return view('pages.settings.index',compact('setting'));
}
and here is my blade that views the form
<form enctype="multipart/form-data" method="post" action="{{route('settings.update','test')}}">
@csrf @method('PUT')
<div class="row">
<div class="col-md-6 border-right-2 border-right-blue-400">
<div class="form-group row">
<label class="col-lg-2 col-form-label font-weight-semibold">اسم المدرسة<span class="text-danger">*</span></label>
<div class="col-lg-9">
<input name="school_name" value="{{ $setting['school_name'] }}" required type="text" class="form-control" placeholder="Name of School">
</div>
</div>
<div class="form-group row">
<label for="current_session" class="col-lg-2 col-form-label font-weight-semibold">العام الحالي<span class="text-danger">*</span></label>
<div class="col-lg-9">
<select data-placeholder="Choose..." required name="current_session" id="current_session" class="select-search form-control">
<option value=""></option>
@for($y=date('Y', strtotime('- 3 years')); $y<=date('Y', strtotime('+ 1 years')); $y++)
<option {{ ($setting['current_session'] == (($y-=1).'-'.($y+=1))) ? 'selected' : '' }}>{{ ($y-=1).'-'.($y+=1) }}</option>
@endfor
</select>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label font-weight-semibold">اسم المدرسة المختصر</label>
<div class="col-lg-9">
<input name="school_title" value="{{ $setting['school_title'] }}" type="text" class="form-control" placeholder="School Acronym">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label font-weight-semibold">الهاتف</label>
<div class="col-lg-9">
<input name="phone" value="{{ $setting['phone'] }}" type="text" class="form-control" placeholder="Phone">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label font-weight-semibold">البريد الالكتروني</label>
<div class="col-lg-9">
<input name="school_email" value="{{ $setting['school_email'] }}" type="email" class="form-control" placeholder="School Email">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label font-weight-semibold">عنوان المدرسة<span class="text-danger">*</span></label>
<div class="col-lg-9">
<input required name="address" value="{{ $setting['address'] }}" type="text" class="form-control" placeholder="School Address">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label font-weight-semibold">نهاية الترم الاول </label>
<div class="col-lg-9">
<input name="end_first_term" value="{{ $setting['end_first_term'] }}" type="text" class="form-control date-pick" placeholder="Date Term Ends">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label font-weight-semibold">نهاية الترم الثاني</label>
<div class="col-lg-9">
<input name="end_second_term" value="{{ $setting['end_second_term'] }}" type="text" class="form-control date-pick" placeholder="Date Term Ends">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label font-weight-semibold">شعار المدرسة</label>
<div class="col-lg-9">
<div class="mb-3">
<img style="width: 100px" height="100px" src="{{ URL::asset('attachments/logo/'.$setting['logo']) }}" alt="">
</div>
<input name="logo" accept="image/*" type="file" class="file-input" data-show-caption="false" data-show-upload="false" data-fouc>
</div>
</div>
</div>
</div>
<hr>
<button class="btn btn-success btn-sm nextBtn btn-lg pull-right" type="submit">{{trans('Students_trans.submit')}}</button>
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论