简体   繁体   中英

Route not defined in Laravel 5.2

In My Laravel App I need dispaly collaborators from My collaborators table. I wrote a query on Collaboration Model as follow

public function scopeColabo($query){
 return $query->where('collaborator_id', Auth::user()->id);}

and this is My CollaborationController function for this

public function newCol(){

 $collaborators = Collaboration::colabo()->get();

 return view('collaborators.new')->withCollaboration($collaborators); }

and I have link in My app.blade.php for this display as

<li> <a href="{{ route('collaborators.new') }}">Collaborate</a> </li>

and this is My routes.php

Route::post('projects/{projects}/collaborator', [
'uses' => 'ProjectCollaboratorsController@newCol',
'as'   => 'projects.collaborators.collaborator',]);

but I get following error message

Route [collaborators.new] not defined. (View: C:\Users\fernando\Desktop\c\resources\views\layouts\app.blade.php)

what can I do to fix this problem?

I think the problem is you are indeed trying to call a route that does not exist. In your routes file you are labelling the route 'as' => 'projects.collaborators.collaborator' so with that being said, this should be updated as such:

<li> <a href="{{ route('projects.collaborators.collaborator') }}">Collaborate</a> </li>

EDIT: Apologies, pasted the wrong line of code from your sample. The line above needs to be updated.

I did it with My routes.php paste this code

Route::resource('collaborators', 'ProjectCollaboratorsController');

it is working

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