Laravel路线不再工作

时间:2016-04-19 21:36:27

标签: php laravel

我正在学习Laravel,而我正在忙着建立一个站点(框架版本5.1.34)。我去年9月安装了Homestead,最初在Windows 7上安装,然后升级到Windows 10. Windows 7上的所有功能都运行良好,以后在Windows 10上运行良好(我在Windows 10上遇到了一些问题,我设法解决了),但随后我的路线最近开始表现得很奇怪我的所有路由仍然有效,除了现在出现404错误。路线是:

Route::get('projects/{project}/nodes/{node}/tasks/create', 
['uses' => 'TaskController@taskCreateShow']);

控制器功能是:

public function taskCreateShow(Project $project, Node $node){
    return view('tasks.create')
            ->with('project',$project)
            ->with('user',$this->user)
            ->with('node',$node)
            ->with('all_projects',$this->all_projects);
} // taskCreateShow

如果我运行php artisan route:list,路线仍会像所有其他路线一样显示。我可以添加新的路线,这也很好。模型绑定在引导函数的RouteServiceProvider.php类中定义:

public function boot(Router $router)
{
    parent::boot($router);

    // Route model binding

    $router->model('project', 'resolved7\Project');
    $router->model('user', 'resolved7\User');
    $router->model('node', 'resolved7\Node');
    $router->model('task', 'resolved7\Task');
    $router->model('io', 'resolved7\Io');
}

我能够让这个工作的唯一方法是将路线改为:

Route::get('projects_1/{project}/nodes/{node}/tasks/create', 
['uses' => 'TaskController@taskCreateShow']);

我查看了.htaccess文件,看起来很好。有没有人知道是什么原因导致这种情况发生?我感谢任何帮助或建议。感谢。

* edit:这是routes.php文件:

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
*/

/*=========================================================================
 * General routes
 */

Route::get('/', function(){
    return redirect('index');
});

Route::get('dashboard', function(){
   return 'dashboard';     
});

Route::get('about', function(){
    return view('about')->with('company_name', 'The Resolved 7<sup>th</sup>');
});

Route::get('index', function(){
    return view('index');
});

// Route used to get images from non-public folder
Route::get('images/{filename}', function ($filename)
{
    $path = storage_path() . '/profilepics/' . $filename;

    $file = File::get($path);
    $type = File::mimeType($path);

    $response = Response::make($file, 200);
    $response->header("Content-Type", $type);

    return $response;
});

/* =========================================================================
 * Project specific routes
 * Use controller to re-use construct functions
 */

// Project specific dashboard
Route::get('projects/{project}', ['uses' => 'ProjectController@projectDashboard'])
->where('project','[0-9]+');

// Page from which to create new project
Route::get('projects/create', ['uses' => 'ProjectController@projectCreateShow']);

// Create a new project through post method
Route::post('projects', ['uses' => 'ProjectController@projectCreate']);

// Page from which to edit projects
Route::get('projects/{project}/edit', ['uses' => 'ProjectController@projectEditShow']);

// Update an existing project through put method
Route::put('projects/{project}', ['uses' => 'ProjectController@projectEdit']);

// Page from which a project deletion is confirmed
Route::get('projects/{project}/delete', ['uses' => 'ProjectController@projectDeleteShow']);

// Delete project
Route::delete('projects/{project}', ['uses' => 'ProjectController@projectDelete']);

// Page to show project details
Route::get('projects/{project}/detail', ['uses' => 'ProjectController@projectDetail']);

// Page from which to select users to add as members
Route::get('projects/{project}/members/invite', ['uses' => 'ProjectController@projectAddMembersShow']);

/* =========================================================================
 * User specific routes
 */

// Page to test user
Route::get('users/{user}/test', ['middleware' => 'auth',
'uses' => 'UserController@test']);

// Page to show user
Route::get('users/{user}', ['middleware' => 'auth',
'uses' => 'UserController@show']);

// Page from which to edit user
Route::get('users/{user}/edit', ['middleware' => 'auth', 
'uses' => 'UserController@showUserEdit']);

// Update an existing user through put method
Route::put('users/{user}', ['middleware' => 'auth',
'uses' => 'UserController@userEdit']);

/* =========================================================================
 * Node specific routes
 */

// Page from which to view node
Route::get('projects/{project}/nodes/{node}', 
['uses' => 'NodeController@nodeShow']);

// Page from which to create new node
Route::get('projects/{project}/nodes/create', 
['uses' => 'NodeController@nodeCreateShow']);

// Create a new node through post method
Route::post('projects/{project}/nodes', 
['uses' => 'NodeController@nodeCreate']);

// Page from which to edit nodes
Route::get('projects/{project}/nodes/{node}/edit', 
    ['uses' => 'NodeController@nodeEditShow']);

// Update an existing node through put method
Route::put('projects/{project}/nodes/{node}', 
['uses' => 'NodeController@nodeEdit']);

// Page from which a node deletion is confirmed
Route::get('projects/{project}/nodes/{node}/delete',['uses' => 'NodeController@nodeDeleteShow']);

// Delete node
Route::delete('projects/{project}/nodes/{node}', ['uses' => 'NodeController@nodeDelete']);

// Page from which a user is selected to be added to a node
Route::get('/projects/{project}/nodes/{node}/members/add', 
['uses' => 'NodeController@nodeAddMember']);

// Add existing project member user to specific project node
Route::post('/projects/{project}/nodes/{node}/members/add', 
['uses' => 'NodeController@nodeAddExistingMember']);

// Page to confirm node member removal
Route::get('/projects/{project}/nodes/{node}/members/{user}/remove', 
['uses' => 'NodeController@nodeRemoveMemberShow']);

// Remove node member user from a specific project node
Route::post('/projects/{project}/nodes/{node}/members/{user}/remove', 
['uses' => 'NodeController@nodeRemoveMember']);

/* =========================================================================
 * Task specific routes
 */

// Page from which to view task
Route::get('projects/{project}/nodes/{node}/tasks/{task}', 
['uses' => 'TaskController@show']);

// Page from which to create new task
// return 'dashboard' is a test.
Route::get('/projects/{project}/nodes/{node}/tasks/create', function(){
   return 'dashboard';     
});
/*Route::get('/projects/{project}/nodes/{node}/tasks/create', 
    ['uses' => 'TaskController@taskCreateShow']);*/

// Create a new task through post method
Route::post('/projects/{project}/nodes/{node}/tasks', 
['uses' => 'TaskController@taskCreate']);

// Page from which a task deletion is confirmed
Route::get('projects/{project}/nodes/{node}/tasks/{task}/delete',
['uses' => 'TaskController@taskDeleteShow']);

// Delete task 
Route::delete('projects/{project}/nodes/{node}/tasks/{task}', 
['uses' => 'TaskController@taskDelete']);


/* =========================================================================
 * Io specific routes
 */

// Page from which to create new io
Route::get('/projects/{project}/nodes/{node}/tasks/{task}/ios/create', 
['uses' => 'IoController@ioCreateShow']);

// Create a new io through post method
Route::post('/projects/{project}/nodes/{node}/tasks/{task}/ios/', 
['uses' => 'IoController@ioCreate']);

// Page from which an io deletion is confirmed
Route::get('projects/{project}/ios/{io}/delete',
['uses' => 'IoController@ioDeleteShow']);

// Delete io
Route::delete('projects/{project}/ios/{io}', 
['uses' => 'IoController@ioDelete']);


/* =========================================================================
 * User authentication controllers
 */

Route::controllers([
    'auth' => 'Auth\AuthController',
    'password' => 'Auth\PasswordController',
]);

/* =========================================================================
 * Community
 */

Route::get('/community', ['uses' => 'UserController@community']);

/* Testing routes
 * 
 * =========================================================================
 * 
 */

// Page from which to test project
Route::get('projects/{project}/test', ['uses' => 'ProjectController@test']);

1 个答案:

答案 0 :(得分:0)

谢谢你们,我错过了一条确实优先考虑的路线。我改变了路线:

Route::get('projects/{project}/nodes/{node}/tasks/{task}', 
['uses' => 'TaskController@show']);

为:

Route::get('projects/{project}/nodes/{node}/tasks/{task}', 
['uses' => 'TaskController@show'])
    ->where('project','[0-9]+')
    ->where('node','[0-9]+')
    ->where('task','[0-9]+');

一切都恢复正常。我也许会改变其他一些路线,以使它们更加健壮。