John John - 3 years ago 205
PHP Question

how to get collaborators with project id in Laravel 5.2 in the localhost

I am developing project management application using Laravel 5.2. in My application side bar menus as sidebar.blade.php witch located in views\layouts\partials\sidebar.blade.php

<li><a href="#">Edit Account</a></li>
<li><a href="{{ route('projects.index') }}">Projects</a></li>
<li><a href="{{ route('collaborators.form')}}">Collaborators</a></li>
<li><a href="#">Todos</a></li>


when I click project link in the sidebar pages view existing pages. and now I need add some collaborators to each project when click collaborators link in the sidebar. my collaborators form in view/collaborators/form

<div class="col-md-4" style="border:1px solid #ccc;margin-left:15px;padding:10px;">
<h4 class="page-header">
Collaborators
</h4>
<form class="form-vertical" role="form" method="post" action="">
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label> Add New </label>
<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">Add User</button>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
</div>


my problem is this i need consider when I am in project 10 and I click collaborator link and then I need following localhost url

localhost:8000/project/10/collaborators


My existing routes is this

Route::get('/collaborators', function(){
return view('collaborators.form');
})->name('collaborators.form');


but it is generated only localhost url as

http://localhost:8000/collaborators


how can I manages this?

Answer Source

Maybe I am missing something but are you trying to do this:

Route::get('/project/{project}/collaborators', function(){ 
       return view('collaborators.form'); 
    })->name('collaborators.form');

And use route('collaborators.form', $project)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download