Support the ongoing development of Laravel.io →
Requests Views Forms

Hi. I create my routes like so

Route::model('projects', 'Project');
Route::bind('projects', function($value, $route) {
    return App\Project::whereId($value)->first();
});
Route::resource('projects', 'ProjectsController');

I think it is important to note that if I create all of the functions within my controller immediately, then everything tends to work. If I do only index and create, and then way down the line decide to add an edit, this is when I see the problem. If I restart my project from scratch with the exact same code, from past experience it will work fine.

Anyways, my index function works fine, and this displays a view with the following

{!! Form::open(array('class' => 'form-inline', 'method' => 'DELETE', 'route' => array('projects.destroy', $project->slug))) !!}
    <td>{{ $project->id }}</td>
    <td>{{ $project->projectId }}</td>
    <td>{{ $project->client->clientName }}</td>
    <td>{{ $project->clientStatus }}</td>
    <td>{{ $project->user->userName }}</td>
    <td>{{ $project->contactName }}</td>
    <td>{{ $project->projectName }}</td>
    <td>{!! link_to_route('projects.show', 'Show', array($project->id), array('class' => 'btn btn-info')) !!}</td>
    <td>{!! link_to_route('projects.edit', 'Edit', array($project->slug), array('class' => 'btn btn-info')) !!}</td>
    <td>{!! Form::submit('Delete', array('class' => 'btn btn-danger')) !!}</td>
{!! Form::close() !!}

So there is a link to my edit route in there. My edit function in the controller looks like the following

public function edit(Project $project)
{
     $clients = Client::lists('clientName', 'id');
     $users = User::lists('userName', 'id');
     return View::make('projects.edit', compact('project', 'clients', 'users'));
}

I have a show function in the same controller which uses the Project variable, and this works fine. If I click on the edit link, it takes me to a page with the url http://localhost:8000/projects//edit, so it is missing the id between projects and edit. If I add an id in manually, I can see the page.

My routes appear ok.

GET|HEAD | projects/{projects}/edit               | projects.edit           | App\Http\Controllers\ProjectsController@edit         |

I seem to have a problem with this edit call for some reason though, but as I say, if I restart the project I bet the code I have works. I have tried clearing the cache, doing any bit of advice I could find on the internet.

Is there any reason why this might be happening?

Thanks

Last updated 3 years ago.
0

It looks like you're passing the slug and not the id.

0

Oh my, been going over this for so long. I didnt create a slug for my projects table even though my other tables have one. And because I am using similar code to my other tables, the slug was included.

Thanks for spotting that.

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

nick2price nick2price Joined 20 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.