引导模式中的未定义变量 - Laravel
Undefined variable in boostrap modal - Laravel
我在 bootstrap 模态中有一个 $room
变量,它导致了问题。
这里是reservationController
中的函数:
public function create()
{
$room = Room::all();
return view('/allReservationChild', compact('room'));
}
blade 名称是 allReservationChild.blade.php
,这是模态的一部分:
<div class="modal fade" id="addres" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Delete Room</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form style="margin: 50px; text-transform: capitalize " action="/addReservation" method="POST" class="needs-validation" novalidate >
@csrf
<div class="modal-body">
<div class="form-group">
<label for="exampleFormControlSelect1">Select the Room you want to reserve</label>
<select class="form-control" id="exampleFormControlSelect1" name="room_id" required>
<option value=""></option>
@foreach($room as $items)
<option value="{{$items->id}}">{{$items->id}}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="exampleFormControlTextarea1" class="form-label">Objectif :</label>
<select class="form-control" id="exampleFormControlTextarea1" name="objectif" required>
<option value=""></option>
<option value="Booking room for a replacement session ">Booking room for a replacement session </option>
<option value="Booking room for a random session">Booking room for a random session</option>
<option value="Booking room for an event">Booking room for an event</option>
<option value="Booking room for an exam">Booking room for an exam</option>
<option value="Booking room for discussion of the graduation thesis">Booking room for discussion of the graduation thesis</option>
<option value="other">other</option>
</select>
</div>
<div class="form-group">
<label class="control-label">Reservation date</label></br>
<input class="form-control" type="date" id="Date_beginning" name="date" required>
</div>
<div class="form-group">
<label for="time">Select time period</label>
<select class="form-control" id="time" name="time" required>
<option value=""></option>
<option value="8:30-10:30">8.30-10.30</option>
<option value="10:30-12:30">10.30-12.30</option>
<option value="13:30-15:30">13.30-15.30</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-outline-danger" name="supp" >Add Reservation</button>
</div>
</form>
</div>
</div>
</div>
路线是:
Route::get('/addReservation', [\App\Http\Controllers\reservationController::class,'create']);
不知道为什么不能定义$room
变量。我认为是因为模态什么的。
而且我确定模态是正确的,因为我在另一个 blade 中使用了相同的模态并且它工作得很好所以我认为问题出在控制器或网络中,我不确定。
编辑:我有一个预订模式 table,当用户点击添加新预订时弹出窗口应该出现,然后他会选择一个现有的房间
我对查看路径不太自信。你可以试试这个案例
public function create()
{
$room = Room::all();
return view('/allReservationChild', ["room"=>$room] );
}
希望对你有用
示例它对我来说在实时项目中有效
public function index()
{
$educationList = Cache::rememberForever('educationList', function () {
return EducationMaster::where('education_status', 1)->get();
});
return view('Admin.pages.Masters.EducationMaster.index', ['educationList' => $educationList]);
}
我的看法
<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="staticBackdropLabel">
{{ __('common.add new') }}-{{ __('masters.City') }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<form action="{{ route('admin.city.store') }}" method="post">
@csrf
<div class="modal-body">
<div class="container">
<div class="row">
<div class="col">
<label class="form-label">{{ __('masters.City') }}</label>
<input type="text" name="city_name" class="form-control" required>
</div>
</div>
<div class="row">
<div class="col">
<div class="mb-3">
<div class="form-label">{{ __('masters.State') }}</div>
<select class="form-select" name="state_id" required>
<option value="">Choose The State</option>
@foreach ($stateList as $state)
<option value="{{ $state->id }}">{{ $state->state_name }}
</option>
@endforeach
</select>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-square-x"
width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"
fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<rect x="4" y="4" width="16" height="16" rx="2"></rect>
<path d="M10 10l4 4m0 -4l-4 4"></path>
</svg>
{{ __('common.cancel') }}</button>
<button type="submit" class="btn btn-primary " x-on:click="addNewRasi()">
<svg xmlns="http://www.w3.org/2000/svg"
class="icon icon-tabler icon-tabler-device-floppy" width="24" height="24"
viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2">
</path>
<circle cx="12" cy="14" r="2"></circle>
<polyline points="14 4 14 8 8 8 8 4"></polyline>
</svg>
{{ __('common.save') }}</button>
</div>
</form>
</div>
</div>
</div>
``
您的变量已定义,这是由于缓存问题导致的,请使用以下命令清除缓存。
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
我在 bootstrap 模态中有一个 $room
变量,它导致了问题。
这里是reservationController
中的函数:
public function create()
{
$room = Room::all();
return view('/allReservationChild', compact('room'));
}
blade 名称是 allReservationChild.blade.php
,这是模态的一部分:
<div class="modal fade" id="addres" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Delete Room</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form style="margin: 50px; text-transform: capitalize " action="/addReservation" method="POST" class="needs-validation" novalidate >
@csrf
<div class="modal-body">
<div class="form-group">
<label for="exampleFormControlSelect1">Select the Room you want to reserve</label>
<select class="form-control" id="exampleFormControlSelect1" name="room_id" required>
<option value=""></option>
@foreach($room as $items)
<option value="{{$items->id}}">{{$items->id}}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="exampleFormControlTextarea1" class="form-label">Objectif :</label>
<select class="form-control" id="exampleFormControlTextarea1" name="objectif" required>
<option value=""></option>
<option value="Booking room for a replacement session ">Booking room for a replacement session </option>
<option value="Booking room for a random session">Booking room for a random session</option>
<option value="Booking room for an event">Booking room for an event</option>
<option value="Booking room for an exam">Booking room for an exam</option>
<option value="Booking room for discussion of the graduation thesis">Booking room for discussion of the graduation thesis</option>
<option value="other">other</option>
</select>
</div>
<div class="form-group">
<label class="control-label">Reservation date</label></br>
<input class="form-control" type="date" id="Date_beginning" name="date" required>
</div>
<div class="form-group">
<label for="time">Select time period</label>
<select class="form-control" id="time" name="time" required>
<option value=""></option>
<option value="8:30-10:30">8.30-10.30</option>
<option value="10:30-12:30">10.30-12.30</option>
<option value="13:30-15:30">13.30-15.30</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-outline-danger" name="supp" >Add Reservation</button>
</div>
</form>
</div>
</div>
</div>
路线是:
Route::get('/addReservation', [\App\Http\Controllers\reservationController::class,'create']);
不知道为什么不能定义$room
变量。我认为是因为模态什么的。
而且我确定模态是正确的,因为我在另一个 blade 中使用了相同的模态并且它工作得很好所以我认为问题出在控制器或网络中,我不确定。
编辑:我有一个预订模式 table,当用户点击添加新预订时弹出窗口应该出现,然后他会选择一个现有的房间
我对查看路径不太自信。你可以试试这个案例
public function create()
{
$room = Room::all();
return view('/allReservationChild', ["room"=>$room] );
}
希望对你有用
示例它对我来说在实时项目中有效
public function index()
{
$educationList = Cache::rememberForever('educationList', function () {
return EducationMaster::where('education_status', 1)->get();
});
return view('Admin.pages.Masters.EducationMaster.index', ['educationList' => $educationList]);
}
我的看法
<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="staticBackdropLabel">
{{ __('common.add new') }}-{{ __('masters.City') }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<form action="{{ route('admin.city.store') }}" method="post">
@csrf
<div class="modal-body">
<div class="container">
<div class="row">
<div class="col">
<label class="form-label">{{ __('masters.City') }}</label>
<input type="text" name="city_name" class="form-control" required>
</div>
</div>
<div class="row">
<div class="col">
<div class="mb-3">
<div class="form-label">{{ __('masters.State') }}</div>
<select class="form-select" name="state_id" required>
<option value="">Choose The State</option>
@foreach ($stateList as $state)
<option value="{{ $state->id }}">{{ $state->state_name }}
</option>
@endforeach
</select>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-square-x"
width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"
fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<rect x="4" y="4" width="16" height="16" rx="2"></rect>
<path d="M10 10l4 4m0 -4l-4 4"></path>
</svg>
{{ __('common.cancel') }}</button>
<button type="submit" class="btn btn-primary " x-on:click="addNewRasi()">
<svg xmlns="http://www.w3.org/2000/svg"
class="icon icon-tabler icon-tabler-device-floppy" width="24" height="24"
viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2">
</path>
<circle cx="12" cy="14" r="2"></circle>
<polyline points="14 4 14 8 8 8 8 4"></polyline>
</svg>
{{ __('common.save') }}</button>
</div>
</form>
</div>
</div>
</div>
``
您的变量已定义,这是由于缓存问题导致的,请使用以下命令清除缓存。
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear