Laravel Route错误

时间:2016-11-19 00:22:39

标签: php laravel laravel-5.3

好吧,我有这个错误:'路由[setor]未定义'在调用我的视图时,我的路线已配置。

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('SetorController@show', $setor) }}"><span class="glyphicon glyphicon-search"></span></a></td>
                    <td><a href="{{ action('SetorController@edit', $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

由于

1 个答案:

答案 0 :(得分:0)

  1. 如果添加了新的路径文件,请确保在mapWebRoutes()方法
  2. 中引用它
      

    应用\提供商\ RouteServiceProvider.php

    1. 您还可以运行以下命令来检查已注册的路线

      php artisan route:list

    2. 您可以使用以下命令清除路由缓存,然后重试

      php artisan route:clear

    3. 希望这对你有用。