Я пытаюсь выполнить операции CRUD на ресурсе тем. Я создал контроллер ресурсов и правильно управлял функциями индексирования, создания, хранения и отображения. Я впервые делаю CRUD с Laravel. В своей форме я использую поле выбора и флажок группы.
Вот themeEdit
вид лезвия
@extends('layouts.layout')
@section('content')
<form method="PUT">
@csrf
<!-- Intitulé du thème -->
<input type="text" name="intitule" id="intitule" placeholder="Intitulé du thème" value=" {{$theme->intitule}} " required><br>
<!-- Catégorie -->
<select name="categorie" required>
<option value="">-- Catégorie --</option>
<option value="web">Développement web</option>
<option value="appMobile">Programmation application mobile</option>
<option value="secure">Sécurisation</option>
<option value="other">Autre</option>
</select> <br>
<!-- Filière désirée -->
<input type="checkbox" name="filiere[]" id="GL" value=" {{$theme->filiereDesiree}} " required>
<label for="GL">Génie Logiciel</label><br>
<input type="checkbox" name="filiere[]" id="SI" value=" {{$theme->filiereDesiree}} " required>
<label for="SI">Sécurité Informatique</label><br>
<input type="checkbox" name="filiere[]" id="IM" value=" {{$theme->filiereDesiree}} " required>
<label for="IM">Internet et Multimédia</label><br>
<input type="checkbox" name="filiere[]" id="SIRI" value=" {{$theme->filiereDesiree}} " required>
<label for="SIRI">Systèmes d'Information et Réseaux Informatiques</label><br>
<!-- Descriptif -->
<textarea name="description" id="description" placeholder="Description de la thématique" required> {{$theme->description}} </textarea><br>
<input type="submit" name="submit" id="submit" value="Ajouter">
<span id="error-message" class="text-danger"></span>
<span id="success-message" class="text-success"></span>
</form>
@endsection
Я передаю данные для просмотра через контроллер в функции редактирования
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$theme = Theme::findOrFail($id);
return view('themeEdit', ['theme' => $theme]);
}
Я попробовал то, что вы видели в представлении кода выше, чтобы проверить, можно ли установить или снять флажки в соответствии с данными в базе данных. Он не делает то, что ожидается ..
<!-- Filière désirée -->
<input type="checkbox" name="filiere[]" id="GL" value=" {{$theme->filiereDesiree}} " required>
<label for="GL">Génie Logiciel</label><br>
<input type="checkbox" name="filiere[]" id="SI" value=" {{$theme->filiereDesiree}} " required>
<label for="SI">Sécurité Informatique</label><br>
<input type="checkbox" name="filiere[]" id="IM" value=" {{$theme->filiereDesiree}} " required>
<label for="IM">Internet et Multimédia</label><br>
<input type="checkbox" name="filiere[]" id="SIRI" value=" {{$theme->filiereDesiree}} " required>
<label for="SIRI">Systèmes d'Information et Réseaux Informatiques</label><br>
Если это может быть полезно, я храню данные в базе данных через функцию контроллера хранилища
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$theme = new Theme;
$theme->intitule = $request->input('intitule');
$theme->description = $request->input('description');
$theme->categorie = $request->input('categorie');
$request->merge([
'filiere' => implode(',', (array) $request->get('filiere'))
]);
$theme->filiereDesiree = $request->input('filiere');
$theme->save();
echo "Enregistré";
}
Что я хочу знать, так это как получить выбранные или проверенные данные из базы данных и правильно их извлечь в соответствующем поле в представлении.