简体   繁体   English

如何在Laravel 5.2中路由子任务URL?

[英]How to route subtasks URL in Laravel 5.2?

I am working with laravel 5.2 and I am developing project management tool. 我正在使用laravel 5.2,正在开发项目管理工具。 in my application I have projects and each project have tasks and one task may have sub tasks. 在我的应用程序中,我有项目,每个项目都有任务,一个任务可能有子任务。 in each task I have button to create subtasks as following, 在每个任务中,我都有创建以下子任务的按钮,

<a href="" class="editInline"><i class="glyphicon glyphicon-plus"></i></a>

when I view my tasks list witch related to each project my url is as following. 当我查看与每个项目相关的任务列表列表时,我的网址如下。

http://localhost:8000/projects/1

now i have subtask form in subtasks folder of view file to enter sub tasks to each task 现在我在视图文件的subtasks文件夹中有subtask形式,可以为每个任务输入子任务

subtasks/subtask.blade.php

now I need when I click sub task enter button redirect subtask blade file as url is this way. 现在,当我单击子任务时,我需要输入按钮重定向子任务刀片文件,因为这种方式是url。

http://localhost:8000/projects/1/task/1/subtask

how can I manage href of sub task add button 我如何管理子任务添加按钮的href

<a href="" class="editInline"><i class="glyphicon glyphicon-plus"></i></a> 

and My routes? 和我的路线? Updated this is my subtask input form 更新这是我的子任务输入表单

<form class="form-vertical" role="form" method="post" action="{{ route('projects/{projectId}/task/{taskId}/subtask')}}">
            <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
                <input type="text" name="task_name" class="form-control" id="name" value="{{ old('task_name') ?: '' }}">
                @if ($errors->has('task_name'))
                    <span class="help-block">{{ $errors->first('task_name') }}</span>
                @endif
            </div>

            <div class="form-group">
                <button type="submit" class="btn btn-info">Create Task</button>
            </div>
            <input type="hidden" name="_token" value="{{ csrf_token() }}">
        </form>

is my subtask form action correct? 我的子任务表单操作正确吗?

You can create route like this 您可以像这样创建路线

http://localhost:8000/projects/1/task/1/subtask

Route::get('projects/{projectId}/task/{taskId}/subtask','HomeController@index');

For link 对于链接

<a href="{{url('projects/'.$projectId.'/task/'.$taskId.'/subtask')}}" class="editInline"><i class="glyphicon glyphicon-plus"></i></a>`

so in controller you can access 因此在控制器中您可以访问

public function index($projectId,$taskId){

//you can do your query releated task
} 

Update if you have not developed controller and you wish to pass via route then 如果您尚未开发控制器并希望通过路线通过,请更新

Route::get('projects/{projectId}/task/{taskId}/subtask', function ($projectId, $taskId) {

    return view('subtasks/subtask',['projectId'=>$projectId,'taskId'=>$taskId]);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM