Я пытаюсь передать anINT
с этого URL: myapp.build/courses/anINT
(реализовано в CoursesController
) в $id
в функции Lesson_unitsController
ниже.Я перепробовал множество решений, но, похоже, не могу понять, что это правильно.
Функция в CoursesController, которая реализует URL:
public function show($id)
{
$course = Course::find($id);
return view('courses.show')->with('course', $course);
}
Часть шоуФайл .blade.php:
@if(!Auth::guest())
@if(Auth::user()->id == $course->user_id)
<a href="/courses/{{$course->id}}/edit" class="btn btn-outline-secondary btn-light">Edit Course</a>
<a href="/lesson_units/specificindex" class="btn btn-outline-secondary btn-light">Lesson Units</a>
{!!Form::open(['action'=> ['CoursesController@destroy', $course->id], 'method' => 'POST', 'class' => 'float-right'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-danger'])}}
{!!Form::close()!!}
@endif
@endif
Функции Lesson_unitsController
:
public function index()
{
$lesson_units = Lesson_unit::orderBy('title','asc')->paginate(10);
return view('lesson_units.index')->with('lesson_units', $lesson_units);
}
public function specificindex($id)
{
$course = Course::find($id);
return view('lesson_units.specificindex')->with('lesson_units', $course->lesson_units);
}
И файл specificindex.blade.php
:
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Dashboard</div>
<div class="card-body">
<a href="/lesson_units/create" class="btn btn-primary">Create lesson unit</a>
<p>
<h3>Your lesson_units</h3>
@if(count($lesson_units) > 0)
<table class="table table-striped">
<tr><th>Title</th><th></th><th></th></tr>
@foreach($lesson_units as $lesson_unit)
<tr><td>{{$lesson_unit->title}}</td>
<td><a href="/lesson_units/{{$lesson_unit->id}}/edit" class="btn btn-outline-secondary btn-light">Edit</a></td>
<td>
{!!Form::open(['action'=> ['Lesson_unitsController@destroy', $lesson_unit->id], 'method' => 'POST', 'class' => 'float-right'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-danger'])}}
{!!Form::close()!!}
</td>
</tr>
@endforeach
</table>
@else
<p>You have no lesson unit.</p>
@endif
@if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif
You are logged in!
</div> </div> </div> </div> </div>
@endsection
Маршруты в web.php:
Route::resource('courses', 'CoursesController');
Route::resource('lesson_units', 'Lesson_unitsController');
Route::get('/courses/{id}', 'Lesson_unitsController@specificIndex');
Я хочу, чтобы при нажатии на ссылку для Lesson Units
на странице id
в URL передавалсяфункция specificindex
в Lesson_unitsController
.Теперь я получаю только пустую страницу.Что я делаю не так?