好吧,我在调用我的视图时遇到此错误:“路线[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
谢谢
根据文档,
Route::resource
生成几条路线。
Route::resource('setor', 'SetorController');
将生成以下命名路由:
setor.index
setor.create
setor.store
setor.show
setor.edit
setor.update
setor.destroy
它不会创建一条名为 setor
的路线,这就是为什么当您执行
{{ route("setor") }}
时会出现错误。从列表中选择合适的一项。您可以使用
php artisan route:list
查看已配置路由的完整列表及其名称(如果适用)。
mapWebRoutes()
内的方法中引用了它
app\Providers\RouteServiceProvider.php
php artisan 路线:列表
php工匠路线:清晰