我收到错误missing required parameters
,它的路线如下:
Route::get('/myunits/{group}/content/{unit}','Users\GroupContentController@show')->name('user.group.unit.show');
当我们重定向到该路由时,该路由是正确的,但是由于某种原因,它失败了。但是,当我在GroupContentController@show
上对参数进行dd()处理时,这些参数就在那里了,所以我不知道错误在哪里。
这是我的控制人
public function show(Group $group , Unit $unit) {
/*
* Check if the user is trying to acces a group
* here he does not belongs.
*/
if ( !UserGroupFacade::IsStudentInGroup($group) ) {
return redirect()->route('user.groups');
}
$data = [];
$groupMaterials = $group->groupMaterials->where("unit_id" , $unit->id);
foreach ($groupMaterials as $gm) {
foreach ($unit->themes as $theme) {
if ($theme->id == $gm->theme_id) {
$theme->show=true;
$material=$theme->materials->where("id" , $gm->material_id)->first();
$material->show=true;
}
}
}
$data['unit'] = $unit;
return view('users.units.show', array('data' => $data));
}
当我执行dd($ group)和dd($ unit)时,一切都在那里,即使我在返回之前尝试了一下,它仍然起作用。
应显示的html如下:
@extends('layouts.main')
@section('title')
Unit
@endsection
@php
$unit = $data['unit'];
@endphp
@section('content')
<section class="goal-app-header-section">
<div class="container">
<div class="image-div float-content left thirty">
<img style="width: 182px; height: 182px; object-fit: contain; border-radius: 50%;" src="{{ $unit->image }}" alt="Unidad">
</div>
<div class="description float-content right seventy">
<h1> {{ $unit->name }} </h1>
<p class="description"> {!! $unit->description !!} </p>
</div>
</div>
</section>
<section class="bars-section">
<div>
<div class="text-center bars blue float-content left half">
<div class="row"><h2> Themes </h2></div>
</div>
<div class="text-center bars green float-content right half">
<div class="row"><h2> Media tools </h2></div>
</div>
</div>
</section>
<section class="content-section">
<input id="view-name" type="hidden" value="single-unit-view">
<div>
<div class="float-content left half">
<?php $number = 0; ?>
@foreach ($unit->themes as $index => $theme)
@if ($theme->show)
<?php $number++; ?>
<div id="{{ $number }}" class="leftArrow inactive">
<div class="row">
<div class="col-xs-12 col-xs-offset-0 col-sm-12 col-sm-offset-0 col-md-1 col-md-offset-1 col-lg-1 col-lg-offset-1">
<div class="numberCircle"><div class="number">{{ $number }}</div></div>
</div>
<div class="col-xs-12 col-sm-12 col-md-10 col-lg-10">
<p class="left">
{{ ($theme->title) }}
</p>
</div>
</div>
</div>
@endif
@endforeach
</div>
<div class="content-list float-content left half">
<?php $number2 = 0; ?>
@foreach ($unit->themes as $index => $theme)
@if ($theme->show)
<?php $number2++; ?>
<div id="course-content-{{ $number2 }}" class="col-xs-12 col-sm-12 col-md-12 col-lg-12 text-left course-content">
@foreach ( $theme->materials as $material )
@if ($material->show)
<div class="row">
<div class="col-height col-xs-12 col-xs-offset-0 col-sm-12 col-sm-offset-0 col-md-1 col-md-offset-1 col-lg-1 col-lg-offset-1">
<svg>
<image style="height: 20px;" href="{{ $material->icon() }}"/>
</svg>
</div>
<div class="col-xs-12 col-sm-12 col-md-10 col-lg-10">
<a target="_blank" href="{{ $material->resource_url }}" class="left">
{{ $material->title }}
</a>
</div>
</div>
@endif
@endforeach
</div>
@endif
@endforeach
</div>
</div>
</section>
@endsection
最后,这是我拨打所需路线的地方
@extends('layouts.main')
@section('title')
My Groups
@endsection
@php
$group = $data['group'];
$units = $data['units'];
@endphp
@section('content')
<section class="goal-title-section">
<div class="container white space-at-bottom">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 text-center">
<h1 class="black">{{ $group->name }}</h1>
<hr class="black">
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 text-center">
<div class="black">
{!! $group->description !!}
</div>
<p class="black">
This group has the folowing units:
</p>
</div>
</div>
<section class="units-grid">
@foreach (array_chunk($units, 4) as $unitsRow)
<div class="row">
@foreach ($unitsRow as $unit)
<div class="col-xs-10 col-xs-offset-2 col-sm-6 col-sm-offset-0 col-md-3 col-md-offset-0 col-lg-3 col-lg-offset-0">
<div class="card text-center">
<img src="{{ $unit->image }}" alt="Unidad">
<h5 class="black">{{ $unit->name }}</h5>
<a href="{{ route('user.group.unit.show', ['group'=>$group->id, 'unit'=>$unit->id])}}" class="btn goal-btn goal-btn-blue goal-btn-small">Read more</a>
</div>
</div>
@endforeach
</div>
@endforeach
</section>
</div>
</section>
@endsection
答案 0 :(得分:6)
您是否可以像这样进行路由并将dd($ group,$ unit)放入控制器中,以查看发送给它的内容。
Route::get('/myunits/{group?}/content/{unit?}','Users\GroupContentController@show')->name('user.group.unit.show');