这是我的第一个使用laravel的应用程序,我是初学者,在工作之前无法显示我的数据 我想要当我单击选择下拉菜单并选择一个班级时 从我尝试过的数据库中带给我这堂课的所有学生 与yajra ajax一起使用,但没有用
我的控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Redirect,Response,DB,Config;
use Datatables;
use App\Matiere;
use App\Eleve;
use App\Note;
use App\Classe;
class NotelController extends Controller
{
public function index()
{
$eleves = Eleve::paginate(5);
$classes = Classe::all();
$notes = Note::all();
$matieres = Matiere::all();
return view('admin.note_eleve',compact('eleves','classes','matieres'));
}
public function store(Request $request)
{
$this->validate($request,[
'note'=>'required',
'matiere_id'=>'required'
'classe_id'=>'required'
'eleve_id'=>'required'
]);
$note = new Note();
$note->note = $request->note;
$matiere_id = $request->matiere_id;
$eleve_id = $request->eleve_id;
$classe_id = $request->classe_id;
if($note->save()){
$note->matieres()->sync($matiere_id);
$note->classes()->sync($classe_id);
$note->eleves()->sync($eleve_id);
session()->flash('success',' cette note a été enregistré avec succés');
}else{
session()->flash('error',' Erreur lors de la sauvegarde de la note');
}
return redirect()->back();
public function usersList()
{
$usersQuery = Classes::query();
$classe = (!empty($_GET["classe"])) ;
$classes = $usersQuery->select('*');
return datatables()->of($classes)
->make(true);
}
}
这是我的观点
<section class="wrapper">
<div class="table-title">
<div class="row">
<div class="col-sm-6">
<h2>Gérér <b></b>notes</h2>
</div>
<div class="col-sm-6">
<a href="#addEmployeeModal"class=" btn btn-success" data-toggle="modal"><i class="material-icons"></i> <span>Ajouter un nouveau note</span></a>
</div>
<div class="col-sm-3">
<div class="form-group">
<select name="father_id" class="form-control filter-select" required>
<option value="">--selectionner la matiere svp --</option>
@foreach($matieres as $matiere)
<option value="{{ $matiere->id }}">{{ $matiere->nom_matiere }} </option>
@endforeach
</select>
</div>
<button type="text" id="btnFiterSubmitSearch" class="btn btn-info">Submit</button>
</div>
<div class="col-sm-3">
<div class="form-group">
<select data-column="0" name="classe_id" class="form-control" required>
<option value="">--selectionner le classe avant svp --</option>
@foreach($classes as $classe)
<option value="{{ $classe->id }}">{{ $classe->classe }} </option>
@endforeach
</select>
</div>
</div>
</div>
</div>
<div class="row mt">
@if(session()->has('success'))
<div class="alert alert-success">
{{session()->get('success')}}
</div>
@endif
<div class="col-lg-12">
<div class="content-panel">
<section id="no-more-tables">
<table class="table table-bordered table-striped table-condensed cf">
<thead class="cf">
<tr>
<th>nom eleve </th>
<th>prenom</th>
<th>nom classe</th>
<th>la note </th>
<th>la matiere </th>
</tr>
</thead>
<tbody>
@foreach($eleves as $eleve)
<tr>
<td class="numeric" data-title="id-note" >{{$eleve->nom}}</td>
<td class="numeric" data-title="Nom">{{$eleve->prenom}}</td>
<td class="numeric" data-title="Nom">{{$eleve->classe->classe}}</td>
<td class="numeric" data-title="Nom">
<input type="text" value ="mettez la note ">
</td>
<td class="numeric" data-title="Nom">
@foreach($eleve->matieres as $matiere)
{{$matiere->nom_matiere}}
@endforeach
</td>
</tr>
</tbody>
@endforeach
</table>
<div class="text-center">
</div>
<script>
$(document).ready( function () {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$('#laravel_datatable').DataTable({
processing: true,
serverSide: true,
ajax: {
url: "{{ url('users-list') }}",
type: 'GET',
data: function (d) {
d.classe = $('#classe').val();
}
},
columns: [
{ data: 'id', name: 'id' },
{ data: 'classe', name: 'classe' ]
});
});
$('#btnFiterSubmitSearch').click(function(){
$('#laravel_datatable').DataTable().draw(true);
});
</script>
</script>
@endsection
```html