0

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?

1 Answer 1

1

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]);
});
Sign up to request clarification or add additional context in comments.

4 Comments

can you give me some idea to create controller to inter subtasks
since you are not using controller .so you can build same way your url as you wish
also you have a option to pass optional parameter in url .you can check documetns

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.