2016-11-19 177 views
0

嗯,我有这个错误:'路由[setor]未定义'时调用我的看法,但我的路线配置。Laravel路由错误

Route::resource('empresa', 'EmpresaController'); 
Route::resource('setor', 'SetorController'); 
Route::resource('departamento', 'DepartamentoController'); 
Route::resource('funcionario', 'FuncionarioController'); 

我的控制器代码:

<?php 

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 
use App\Setor; 

class SetorController extends Controller 
{ 
    /** 
    * Display a listing of the resource. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function index() 
    { 
     $setores = Setor::all(); 
     return view('indicador.setor.index', compact('setores')); 
    } 

    /** 
    * Show the form for creating a new resource. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function create() 
    { 
     return view('indicador.setor.create'); 
    } 

    /** 
    * Store a newly created resource in storage. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @return \Illuminate\Http\Response 
    */ 
    public function store(Request $request) 
    { 
     $setor = Setor::create($request->all()); 
     return redirect('setor'); 
    } 

有配置这种平等和执行其他对象。

而我的观点:

@extends('template.principal') 

@section('pageName') 

    <h1>Setor</h1> 

@endsection 

@section('content') 

    <table class="table">  

     <div class="col-md-3 col-sm-6 hero-feature">  
      <thead> 
      <tr> 
       <th>Setor</th> 
       <th>Empresa</th>  
      </tr> 
      </thead> 
      @foreach($setores as $setor) 
       <tbody> 
       <tr> 
        <td>{{ $setor->nome }}</td> 
        <td>{{ $setor->id_empresa }}</td> 
        <td><a href="{{ action('[email protected]', $setor) }}"><span class="glyphicon glyphicon-search"></span></a></td> 
        <td><a href="{{ action('[email protected]', $setor) }}"><span class="glyphicon glyphicon-pencil"></span></a></td>  
       </tr> 
       </tbody> 
     @endforeach 

     <!--<button href="{{ route('setor.create') }}" type="submit" class="btn btn-default">Adicionar</button>--> 
      <button type="button" onclick="window.location='{{ route("setor") }}'">Adicinar</button> 

     </div>  
    </table>  
@endsection 

感谢

+0

你能发布更多的路线文件或你的控制器吗? – Daniel

+0

没问题,我确实把信息 –

+0

请妥善缩进你的代码。 – Marcs

回答

0
  1. 如果添加一个新的路由文件,确保它在mapWebRoutes()方法引用内部

app\Providers\RouteServiceProvider.php

  • 您也可以运行下面的命令来检查你的注册路线

    PHP工匠路线:列表

  • 你可以使用下面的命令清除路由缓存,然后重试

    PHP工匠路线:明确

  • 希望这对你有用。