Alrighty,所以我必須在我打開我的項目頁面供遊人觀賞:Laravel 5.4路線[project.view]沒有定義
@extends('layouts.master')
@section('title', 'Projects')
@section('content')
<div class="container">
<div class="contact-wrapper ">
<h1 class="text-center">Project overview</h1>
@foreach($projects as $project)
<div class="col-md-4 no-padding">
<div class="project-image col-md-12 no-padding">
<a href="{{ route('project.view', $project->id) }}">
<img src="{{ $project->image }}" class="col-md-12 image">
<p class="image-text">
{{ $project->title }}
</p>
</a>
</div>
</div>
@endforeach
</div>
</div>
@stop
但我會得到以下錯誤:
Route [project.view] not defined. (View: /home/vagrant/Code/test/resources/views/projects.blade.php)
雖然我在web.php路由文件中定義它如下圖所示
<?php
Auth::routes();
Route::get('/', '[email protected]');
Route::group(['middleware' => ['web']], function() {
Route::resource('user', 'UserController', ['only' => ['index', 'show']]);
Route::resource('project', 'ProjectController', ['only' => ['index', 'show', 'view']]);
Route::resource('blog', 'BlogController', ['only' => ['index', 'show']]);
Route::resource('review', 'ReviewController', ['only' => ['index', 'show']]);
});
Route::group(['middleware' => ['auth']], function() {
Route::resource('user', 'UserController', ['only' => ['store', 'update', 'destroy', 'create', 'edit', 'search', 'cms']]);
Route::resource('project', 'ProjectController', ['only' => ['store', 'update', 'destroy', 'create', 'edit', 'search', 'cms']]);
Route::resource('blog', 'BlogController', ['only' => ['store', 'update', 'destroy', 'create', 'edit', 'search', 'cms']]);
Route::resource('review', 'ReviewController', ['only' => ['store', 'update', 'destroy','create', 'edit', 'search', 'cms']]);
Route::get('/home', '[email protected]');
});
,並在我的ProjectController.php我定義的功能笑下面
public function view($id)
{
$projects = Project::findOrFail($id);
$users = User::all();
$userArray = [];
foreach ($users as $user) {
$userArray[$user->id] = $user->username;
}
return view('project.view', compact('projects', 'userArray'));
}
我WN讀過有關如何資源控制器只能處理標準指數/顯示/更新等等等等功能,但我怎麼能這個路線正確所以它會只是我從ProjectController功能?
我有正確的文件夾中的意見,我99%確定我有正確的電話。視圖的路徑是:resources/views/project/view.blade.php
在此先感謝!
你是正確的資源控制器默認路由是laravel定義它的。我的意思是'show','store'等等,當你必須在資源控制器中添加更多的方法時,你必須用'Route :: get('project-view','ProjectController @視圖')'類似的東西。 –