简体   繁体   中英

How to route subtasks URL in Laravel 5.2?

I am working with laravel 5.2 and I am developing project management tool. 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.blade.php

now I need when I click sub task enter button redirect subtask blade file as url is this way.

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

how can I manage href of sub task add button

<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]);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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