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']);
Related
I got confuse and I got an error, why does my routing process not work, The error gives me Route [index] not defined, but on other hand I already defined the index to HomeController, take a look at my process that I did,
Note: I used laravel version: 5.8*
I create a index.blade.php
Add the routes to the web.php and I used this code
`Route::get('/index', 'HomeController#index');
I add the public function index to the HomeController
Web.php
Route::get('/index', 'HomeController#index');
HomeController
public function index()
{
return view('index');
}
My URL:
Error:
The problem might be in your index view.
Looks like you are trying to access route using route name and you have not defined the route name for index route.
So in web.php add ->name('index')
Route::get('/index', 'HomeController#index')->name('index');
You have to provide name of the route in your routes.
Route::get('/index', 'HomeController#index')->name('index');
You can also use the below syntax
Route::get('/index', [
'as' => 'index',
'uses' => 'HomeController#index'
]);
for more information please have a look at the docs
https://laravel.com/docs/5.7/routing#named-routes
Try This
if you use route this way
Route::get('/index', 'HomeController#index');
//then your url will be
URL/index
OR use this way
Route::get('/', 'HomeController#index');
//then your url will be
URL
Try with localhost/folder_name/public/index if this works for you then probably problem is with virtual host creation.
Somewhere in your view you are using {{route('index')}}.
Add ->name('index') in the end of your route.
Route::get('/index', 'HomeController#index')->name('index');
Hope this will help.
So I'm working with two Resource Controllers (I'm not sure if that's the problem but if it is, please let me know); one of them is StudentController and its URL is "/main". It's working as it should, perfectly. Now I'm creating the 2nd Resource Controller which name is TeacherController, and its URL is "teacher/main" - i.e its files are in the 'teacher' folder. This is my web routes file:
Web.php:
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Route::resource('/main','StudentController');
Route::get('profile','ProfileController#index')->name('profile');
Route::get('profile/edit','ProfileController#edit')->name('profile/edit');
Route::put('profile/edit/{id}','ProfileController#update')->name('profile.update');
Route::resource('teacher/main','TeacherController');
Now when I go to teacher/main - it says that "teacher.main.create" is not defined. That is the route that I've used on my create button i.e
{{ link_to_route('teacher.main.create','Add a Teacher','',['class'=>'btn btn-success float-right']) }}
And this is the create() function in my Resource Controller:
public function create()
{
return view ('teacher/create');
}
From my understanding of Laravel Resource Controllers, I shouldn't have to define each Resource Controller function individually as Laravel should automatically detect each of them since I've already defined Route::resource('teacher/main','TeacherController'); in my Web Routes. What am I doing wrong here? This is just the first function it's getting, then there are other functions like Edit/Destroy that will also pop-up route errors and I don't want to go through with defining each of them individually. Help is highly appreciated.
Try to use in group with prefix and as
Route::group(['prefix' => 'teacher','as'=>'teacher.'], function () {
Route::resource('main','TeacherController');
});
Now you can use teacher.main.create
{{ link_to_route('teacher.main.create','Add a Teacher','',['class'=>'btn btn-success float-right']) }}
I just tested this locally, and seems like you're using wrong name for your resource route. I set the routes exactly as in your example, and this is what I got:
So if you wanted to use the create route, you'd do it like this:
{{ link_to_route('main.create','Add a Teacher','',['class'=>'btn btn-success float-right']) }}
On the other hand, if you want to keep the names you wanted, you can set a custom name for each of your resource route, like this:
Route::resource('teacher/main', 'TeacherController', [
'names' => [
'index' => 'teacher.main.index',
'create' => 'teacher.main.create',
// etc...
]
]);
Hope this helps. Happy coding.
Route::resource('teacher-main','TeacherController');
now you can access
teacher-main.index
I am trying to set up a Laravel route group in Laravel 5.5 and use it in a blade. However I am getting the a Route not defined error. The full error is :
"Route [admin/route_group_test] not defined. (View: C:\Users\Joey\Web\jrd_dnd_tools\resources\views\layouts\navigation.blade.php) (View: C:\Users\Joey\Web\jrd_dnd_tools\resources\views\layouts\navigation.blade.php) (View: C:\Users\Joey\Web\jrd_dnd_tools\resources\views\layouts\navigation.blade.php)
I have looked through the documentation and it looks like I am doing it right. Here is the line from the route file:
Route::prefix('admin')->group(function(){
Route::get('route_group_test','AdminController#testingMiddleWare');
});
and the link from the blade:
{{route('admin/route_group_test')}}
I have no idea what I am doing wrong
The route() helper uses route's name. From the docs:
The route function generates a URL for the given named route
So you need to name the route:
Route::get('route_group_test', 'AdminController#testingMiddleWare')->name('admin.route_group_test');
Or:
Route::get('route_group_test', ['as' => 'admin.route_group_test', 'uses' => 'AdminController#testingMiddleWare']);
And then use it:
{{ route('admin.route_group_test') }}
Or you can use unnamed route:
{{ url('admin/route_group_test') }}
Try the below code:
Route::group(['prefix'=>'admin','namespace'=>''], function () {
Route::get('route_group_test','AdminController#testingMiddleWare');
});
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
I'm using the extension laravel-menu in my Laravel application.
This application contains multiple projects with multiple locations attached to each project.
Now I want to define a sidemenu where I can among other manage the locations.
The url of a project is
project/1
The url of the locations page of a project is
project/1/locations
How to setup this side menu in routes.php?
My routes.php code:
Route::resource('project', 'ProjectsController'));
Route::resource('project.locations', 'LocationsController');
Menu::make('sidemenu-project', function($menu) {
$menu->add('Locaties', array('route' => 'project.locations.index','{project?}'))->data('id',1); // this is not working
});
This is outputting the url /project/%7Bproject%7D/locations
Go to your terminal (Command Prompt) and run following command:
> php artisan routes
Then you'll see all the declared routes with their URL and corresponding route name and method name.
I'm very new to Laravel but the Routes page of documentation mentions you create a controller with parameters like this:
Route::get('user/{id}', function($id) { ... });
could you therefore define your route as
Route::get('project/{id}/locations', function($id) { ... });
I think you have this issue due to misconfiguring the routes. To achieve the route structure that you want, you should put your project/1/locations route definition above the first one. Consider your routes.php to be:
Route::resource('project/{project}/locations', ['as'=>'project.locations', 'uses'=> 'LocationsController']);
Route::resource('project', 'ProjectsController'));