Laravel link to Controller
12,703
Solution 1
Actualy Laravel
will create following routes
Route(URL) | Name
------------------------------------------------------------------
GET profile | profile.index
GET profile/create | profile.create
POST profile | profile.store
GET profile/{profile} | profile.show
GET profile/{profile}/edit | profile.edit
PUT profile/{profile} | profile.update
PATCH profile/{profile} |
DELETE profile/{profile} | profile.destroy
For this
Route::resource('profile' , 'ProfileController' , array('as'=>'profile' , 'before'=>'csrf'));
If you run php artisan routes
from your terminal/command prompt then you'll get all the route's list with name
and url
.
Solution 2
Probably you'll have to:
<li><a href="{{ URL::route('profile.index') }}"> Profile Managment </a></li>
To be sure, execute
php artisan routes
Laravel will show the list of routes and names you have to use.
Also, you have access to more info in the docs: http://laravel.com/docs/controllers#resource-controllers
Author by
DolDurma
Updated on June 04, 2022Comments
-
DolDurma almost 2 years
i have this menu item such as :
<li><a href="{{ URL::route('profile') }}"> Profile Managment </a></li>
and i want to route that to
ProfileController
. this below my route do not work.Route::resource('profile' , 'ProfileController' , array('as'=>'profile' , 'before'=>'csrf'));
i want to route that if user can login and can see profile page and that nust be send all Request to ProfileController.
Error Result:
Error in exception handler: Route [profile] not defined. (View: /var/www/laravel/app/views/back_end/menu.blade.php) (View: /var/www/laravel/app/views/back_end/menu.blade.php) (View: /var/www/laravel/app/views/back_end/menu.blade.php) in /var/www/laravel/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:207
-
DolDurma about 10 yearsmy profile view is under view/back_end/layouts and
URL::route('profile.index')
for link to ProfileController withhttp://localhost/laravel/public/admin/profile
link. i get this error:Route [profile.index] not defined.
-
The Alpha about 10 yearsRun
php artisan routes
to be sure you have a route asprofile.index
and also, runcomposer dump-autoload
to update the autoload class. -
DolDurma about 10 yearsthanks. my form action is
ProfileController@profile
and in ProfileController i have this action:public function profile(){ print_r(Input::all());}
. i get this error now.Route [ProfileController@profile] not defined.
-
The Alpha about 10 yearsTo submit the form to
store
method you should use{{ Form::open(array('route' => 'profile.create', 'method' => 'post')) }}
or you may useaction="{{ route('profile.store') }}" method="POST"
. -
The Alpha about 10 yearsIf you want to submit the form to the
profile
method then it needs a route. -
DolDurma about 10 yearsthanks after change route to
admin.profile.create
my url changed tohttp://localhost/laravel/public/admin/profile/{profile}
and i get this error:NotFoundHttpException
. My form is:http://paste.debian.net/79337/
. My Route:http://paste.debian.net/79339/
-
The Alpha about 10 yearsWhat you are trying to do, where you want to submit the form, did you use
Form
class ofLaravel
, if not then use it, check the documentation. -
DolDurma about 10 yearsdid you try to see my links? i'm using laravel opening form with Blade.
http://paste.debian.net/79337/
-
The Alpha about 10 yearsDo you have a route named as
admin.profile.update
? -
DolDurma about 10 yearsmy problem is that. why i must be have route? i want to send form to controller directly.i must define route for that?
-
The Alpha about 10 yearsThis is the easiest way, you can use
url
likearray('url' => 'profile/update/1', 'method' => 'post'))
, this route needs anid
of the record you want to update. -
The Alpha about 10 yearsWith route,
array('route' => array('profile.update', $someModel->id), 'method' => 'post'))
. -
DolDurma about 10 yearsi'm sorry how to fix this route? can you help me?
Route::post('/admin/profile/{id}',array('as'=>'admin.profile.update',function($id){}));
-
The Alpha about 10 yearsSorry! I don't get it, you suppose to use
resource
controller's route according to your question. -
DolDurma about 10 yearsyes. i'm using
Route::resource
and i can not resolve this problem. -
The Alpha about 10 yearsThen you don't need to use
Route::post('/admin/profile/{id}',array('as'=>'admin.profile.update',function($id){}));
, remove it and use the update function insideProfileController
for updating and use{{ Form::open(array('route' => array('profile.update', $someModel->id), 'method' => 'post')) }}
.