I cannot get the named routes to resolve in my controllers. I am very new to Laravel so I am sure I missed something obvious. Any help is appreciated.
I have the following code in routes.php:
Route::get('password/email', ['uses' => 'Auth\PasswordController#getEmail', 'as', 'session.getEmail']);
Then in one of the Controllers I want to extract the route and place it in a variable I am passing to a blade template like this:
$forgot_password_link = route('session.getEmail');
return view('auth.login', compact('logo', 'forgot_password_link'));
This is then used in the form like this:
Forgot Your Password?
But I get the following error when I load the page:
InvalidArgumentException in UrlGenerator.php line 278:
Route [session.getEmail] not defined.
'as', 'session.getEmail'
this should be key=>value pair
Related
Laravel version has updated and the routes is now expecting an object instead of an id from when i last used it.
My Routes:
When I try to pass over the $item object which the method in the controller wants. I get a 404 not found and my logs aren't returning... meaning the function isn't running. When the $item obj is not passed over the function realizes that a parameter is missing thus the method is recognized by the blade as being the same as the one in the controller.
Calling the edit function in Blade:
Controller Code:
I appreciate any help whatsoever.
The order of your routes is probably wrong
when you first define the show route with /item/{item} and then create with /item/create laravel will think the "create" is the id (or reference)
best way is to have
the index
create
....
show
Code Example correct
Route::get('/', ProductIndex::class)->name('product.index');
Route::get('/new', ProductCreate::class)->name('product.create');
Route::get('/{product}', ProductShow::class)->name('product.show');
Code Example wrong
Route::get('/', ProductIndex::class)->name('product.index');
Route::get('/{product}', ProductShow::class)->name('product.show');
Route::get('/new', ProductCreate::class)->name('product.create');
I have the followning method in my controller:
public function showQualityResult($qualityData) {
return $qualityData;
}
When clicked on a link , i want that method to be invoked , so i have the following in my view file:
Submited Quality Check
Also, I have the following route setup:
Route::get('/showQualityResult', 'QualityCheckController#showQualityResult');
But having the below line of code:
Submited Quality Check
Does't really work , i get the following error in the frontEnd:
Now how can i solve this problem , and why am i getting this error of Route not defined , even though i have the route defined ??
route() helper uses route name to build URL, so you need to use it like this:
route('quality-result.show', session('quality-data'));
And set a name for the route:
Route::get('/showQualityResult', ['as' => 'quality-result.show', 'uses' => 'QualityCheckController#showQualityResult']);
Or:
Route::get('/showQualityResult', 'QualityCheckController#showQualityResult')->name('quality-result.show');
The route function generates a URL for the given named route
https://laravel.com/docs/5.3/routing#named-routes
If you don't want to use route names, use url() instead of route()
The route() helper looks for a named route, not the path.
https://laravel.com/docs/5.3/routing#named-routes
Route::get('/showQualityResult', 'QualityCheckController#showQualityResult')
->name('showQualityResult');
Should fix the issue for you.
In my case I had simply made a stupid mistake.
Further down in my code I had another named route (properly named with a unique name) but an identical path to the one Laravel told me it couldn't find.
A quick update to the path fixed it.
I am trying to send all undefined routes in a specific controller like this:
Route::get('/{slug:[A-Za-z0-9:/]+}', ['uses' => '\Site\Http\Controllers\AppController#index'])
It works in Lumen 5.1 but no chance in Laravel 5.2.
How can I setup such general match routes?
I didn't test it, but something like this should work:
Route::get('/{slug}', 'AppController#index')->where('slug', '([A-Za-z0-9:/]+)');
Put this after all of the relevant other routes:
Route::get('/{slug}', '\Site\Http\Controllers\AppController#index');
Route Undefined = 404 Error, so you can handle it properly.
Look at this question:
Redirect to homepage if route doesnt exist in Laravel 5
I'm trying to use the breadcrumbs by davejamesmiller
In the breadcrumbs.php file which is in the same directory as of route.php I have setup up this:
<?php
Breadcrumbs::register('courses', function($breadcrumbs) {
$breadcrumbs->push('Courses', route('courses')); });
and in the route.php I have:
Route::get('/courses', 'CoursesController#index');
and in the courses.index I called the breadcrumbs like this:
{{ Breadcrumbs::render('courses') }}
But I'm getting an error as follows:
Route [courses] not defined. (View: C:\wamp\www\lc2\laravel\app\views\courses\index.blade.php)
What might be the problem? I cant seem to figure out. I already have the route set for the courses.
i think you have to use laravel named routes - documentation , also in github repo readme
Route::get('/courses', ['uses' => 'CoursesController#index', 'as' => 'courses']);
I'm doing rest api with laravel 4 and I'm getting this error:
Unable to generate a URL for the named route "regions.index"
as such route does not exist.
My router:
Route::group(array('prefix' => 'api/v1'), function(){
Route::get('regions', 'RegionsController#index');
Route::get('regions/{id}', 'RegionsController#getOne');
Route::get('regions/{id}/cities', 'RegionsController#getCities');
});
api/v1/regions and api/v1/regions/1/cities
are working fine
but api/v1/regions/1 is not working and thows exception, I really don't know why and can't find how to make it work.
You have not named your routes.
You should change
Route::get('regions', 'RegionsController#index');
to
Route::get('regions', array('as'=>'regions.index', 'uses'=> 'RegionsController#index');
Thank's for answer, I did solve it. I'm stupid and I call in controller route which I previously deleted. :(
I called in controller:
return View::make('regions.index', compact('regions'));
and regions.index was deleted