ID位于URL中心时的URL路由

I am using laravel 5.6. I want to create a project and add tasks of project. I write the following code for routing a file.

Route::resource('project/{pid}/tasks','TaskController');

If I write a static URL like example.com/project/1/tasks I am getting the task list of project 1. On project list page, I used the following code:

$pid=$project->id;
<a href="{{ route('project/{$pid}/tasks') }}" class="btn btn-primary btn-xs"><i class="fa fa-tasks"></i> Tasks </a>

but It is showing a routing error. How to get project id on task controller?

Try this :

@php
    $pid=$project->id;
@endphp
<a href="{{ url('project/'.$pid.'/tasks') }}" class="btn btn-primary btn-xs"><i class="fa fa-tasks"></i> Tasks </a>

You should use url(), you can use route() by calling the name of the route.

<a href="{{ url('project/'.$pid.'/tasks') }}" class="btn btn-primary btn-xs"><i class="fa fa-tasks"></i> Tasks </a>
<a href="{{ url('project')}}/{{$pid}}/tasks" class="btn btn-primary btn-xs"><i class="fa fa-tasks"></i> Tasks </a>

You should try this:

<a href="{{ url('project/tasks', $pid) }}" class="btn btn-primary btn-xs"><i class="fa fa-tasks"></i> Tasks </a>
{{ url('/project/tasks/', [$pid]) }}

i think its is bad practice to use relative path. i recommend to you always use link to route because any time if you want to change url .you will need to change it manually.urls could be 100 or 1000 to change.which is dangers for app

{{ route('route name', ['id' => $pid]) }}