Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Index.html
- <body>
- <select id="tasks">
- @foreach($tasks as $task)
- <option value="{{ $task->id }}">{{ $task->title }}</option>
- @endforeach
- </select>
- <select id="subtasks"></select>
- <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
- <script>
- $(document).ready(function () {
- $('#tasks').change(function (ev) {
- var id = ev.target.value;
- $.ajax({
- method: 'GET',
- url: `/tasks/${id}/subtasks`
- }).done(function (response) {
- var subTasks = $('#subtasks');
- $.each(response, function(index, task) {
- subTasks.append($("<option />").val(task.id).text(task.title));
- });
- })
- });
- });
- </script>
- // Route.php
- Route::get('random', function () {
- return view('random', [
- 'tasks' => \App\Task::all()
- ]);
- });
- Route::get('tasks/{task}/subtasks', 'TaskController@subTasks');
- // TaskController
- public function subTasks(Task $task)
- {
- return Task::where('id', '>', $task->id)->get();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement