Help .. Route mix php laravel

0

Something strange happens. It happens that I have three groups of routes one for the admin and the other for secretary and teacher, what happens is that I put the controllers in each one, so that the admin can also see it, but at the time that shows the views, ejm I am in admin mode, in the student view and edit, I get the secretary url. Something that mixes and I do not know how I can solve it.

VISTA

@extends ('layouts.admin')
@section ('contenido')
<div class="row">
    <div class="col-lg-8 col-md-8 col-sm-8 col-xs-12">
        <h4>Lista de Alumnos</h4>
        <a href="alumno/create"><button class="btn btn-success">Nuevo Registro</button></a>
        <h4>@include('matricula.alumno.search')</h4>
    </div>
</div>

<div class="row">
    <div class="col-lg-12 col-md-12 col-xs-12">
        <div class="table-reponsive">
            <table class="table table-striped table-bordered table-condensed table-hover">
                <thead>
                    <th>Nombres</th>
                    <th>Apellidos</th>
                    <th>DNI</th>
                    <th>Fecha Nacimiento</th>
                    <th>Sexo</th>
                    <th>Dirección</th>
                    <th>Telefono</th>
                    <th>Apoderado</th>
                    <th>Opciones</th>
                </thead>
                 @foreach($alumnos as $alu) 
                <tr>
                    <td>{{$alu->nombres}}</td>
                    <td>{{$alu->apellidos_pat}} {{$alu->apellidos_mat}}</td>
                    <td>{{$alu->DNI}}</td>
                    <td>{{$alu->fecha_nac}}</td>
                    <td>{{$alu->sexo}}</td>
                    <td>{{$alu->direccion}}</td>
                    <td>{{$alu->telefono}}</td>
                    <td>{{$alu->nombap}} {{$alu->apellido_pat}} {{$alu->apellido_mat}}</td>
                    <td>
                        <a href="{{URL::action('AlumnoController@edit',$alu->idAlumno)}}"><button class="btn btn-info">Editar</button></a>
                        <a href="" data-target="#modal-delete-{{$alu->idAlumno}}" data-toggle="modal"><button class="btn btn-danger">Eliminar</button></a>
                    </td>
                </tr>
                @include('matricula.alumno.modal')
                @endforeach 
            </table>
        </div>
    {{$alumnos->render()}}
    </div>
</div>
@stop

Route

Route::group(['middleware' =>['auth','administrador'], 'prefix'=>'admin'], function()
{
    Route::resource('añolectivo','AñolectivoController');
    Route::get('matricula/alumno', 'AlumnoController@index');
    Route::get('matricula/alumno/{id}', 'AlumnoController@edit');
    Route::delete('matricula/alumno/{id}', 'AlumnoController@destroy');
    Route::resource('matricula/registro','RegistroController'); 
    Route::resource('matricula/apoderad','ApoderadController');
    Route::resource('ambiente','AmbienteController');
    Route::resource('tambiente','TipoAmbienteController');

    Route::get('/', 'HomeController@index')->name('home');
});

Route::group(['middleware' =>['auth','secretario'], 'prefix'=>'secretaria'], function()
{
    Route::get('matricula/alumno', 'AlumnoController@index');
    Route::get('matricula/alumno/{id}', 'AlumnoController@edit');
    Route::resource('matricula/registro','RegistroController'); 
    Route::resource('matricula/apoderad','ApoderadController');
    Route::get('/', 'HomeController@index')->name('home');
});

Route::group(['middleware' =>['auth','docente'], 'prefix'=>'docente'], function()
{
    Route::get('/', 'HomeController@index')->name('home');
    //Asitencias
    Route::get('cursos', 'AsistenciaController@cursoasig');
    Route::get('asistencia/{id}', 'AsistenciaController@precreate');
    Route::get('asistenciac/{id}', 'AsistenciaController@create');
    Route::post('asistencia/{id}', 'AsistenciaController@store');
 });

    
asked by Anderson Jamanca 03.12.2017 в 20:46
source

1 answer

0

I think the behavior of Laravel is correct, what you are doing is when registering the Routes you overwrite the Routes of the administrator by those of the secretariat, since the two groups have identical routes. There are several solutions: -

You can redefine the routes for the administrator or scretaria. You can name the Routes in the following way ( You have to name all the routes that are identical in admin and secretary ):

 Route::group(['middleware' =>['auth','administrador'], 'prefix'=>'admin'], function()
{
    Route::get('matricula/alumno', 'AlumnoController@index')->name('admin-matricula');
});

Route::group(['middleware' =>['auth','secretario'], 'prefix'=>'secretaria'], function()
{
    Route::get('matricula/alumno', 'AlumnoController@index')->name('secretaria-matricula');
});

and then in the template you can use the route method ('admin-matriucla'). To the route method you can pass parameters to, look at the documentation for the use of the method

<a href="{{route('admin-matriucla')}}"><button class="btn btn-info">Editar</button></a>
    
answered by 03.12.2017 / 21:34
source