0

I got the error missing required parameters, with the following route: Route::get('/myunits/{group}/content/{unit}','Users\GroupContentController@show')->name('user.group.unit.show');

The route is correct when we redirect to that route, but for some reason It fails. But when I do a dd() of the parameters on GroupContentController@show the parameters are there, so I don't understand where is the error.

This is my controller

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));
}

When I did a dd($group) and dd($unit) everything was there, even I tried that before the return and It stills working.

The html that should be displayed is the following:

@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

Finally this is the place when I call the desired route

@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
12
  • post your html code as well Commented Jul 17, 2018 at 0:33
  • The html code is there now Commented Jul 17, 2018 at 0:37
  • where are you calling this route /myunits/{group}/content/{unit} in your view Commented Jul 17, 2018 at 0:41
  • I put that code now, is almost at the end of the last code Commented Jul 17, 2018 at 0:42
  • 1
    okay.do one thing remove one of the paramter from the url and then try to return one and then second again. may be group or unit is empty in your db. Commented Jul 17, 2018 at 0:50

1 Answer 1

7

can you just make route like this and put dd($group,$unit) in your controller to see what you sent to it.

Route::get('/myunits/{group?}/content/{unit?}','Users\GroupContentController@show')->name('user.group.unit.show');
Sign up to request clarification or add additional context in comments.

1 Comment

have you made the parameters optional like what i sent to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.