The below route works fine.
Route::get('/create','HolidaysController#create')->name('createHoliday');
However, it I get the
Route [createHoliday] not defined
error when I place it in a route prefix.
Route::prefix('holidays')->group(function () {
Route::get('/create','HolidaysController#create')->name('createHoliday');
});
I have cleared all config, cache, route and views through the artisan command without any luck.
Cant figure out why it's not working.
using Laravel 7.24
When we use prefix in routes , the prefix also added in the route name
Please try
holidays.createHoliday
Related
I am newbie to laravel and i am working on a project and i have a following situation
lets assume my base url is https://example.com
Now i want to pass a slug(argument) after a base url which means https://example.com/xyz something like that, and i need to do this on multiple times in my project
This is what i'd tried but it is not working it says that route is not defined.
Route::get('{slug?}', [App\Http\Controllers\UiviewsController::class, 'method1'])->name('method1');
Route::get('/method2/{slug?}', function($slug){
return redirect()->route('method1', ['slug'=>$slug]);
});
And also how can i achieve that on which argument which particular method should be called? for example if i have several other routes similar to above one.
how can i achieve this?
Thank you in advance for your help. :)
You should use the fallback system.
Route::fallback(function () {
//
});
Laravel Route fallback official docs
also, beware:
The fallback route should always be the last route registered by your
application.
Other Option:
Also, you can define a parameter as below example
Route::any('{any}', function(){
//...
})->where('any', '.*');
Please Try php artisan route:cache in your terminal then check it again.
I recently started to code my own Admin panel in Laravel.
Every route was working fine, but all of a sudden the /admin route inside the Auth middleware group stopped working properly.
This are my routes inside web.php
My php artisan route:list
And the EntryController#index looks like this:
public function index()
{
//
$entries = Entry::all();
return view('admin.index', ['entries' => $entries]);
}
I'm having this problem for about 2 now, so maybe one of you know the solution.
I think you're having this issue because of how Laravel prioritises its routes.
And I think the culprit might be this route:
Route::get('/{link}', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
When you use {link} you are basically saying: "expect anything in this segment of the URI". Since the /{link} route is placed before the /admin route, and their URIs both contain only one segment, Laravel will try to resolve /{link} first.
Solution: just move the /{link} route below the /admin route. Might be best to just place it at the bottom of the list :D
I am working on laravel7 Project, I want to change default Auth::route() route paths
I have login page and I want to change it to something like: /random/random2/random3/login
but laravel auth comes with "/login". how can I edit it?
If you just want to prefix them, you can wrap it in a route group:
Route::prefix('random/random2/random3/')->group(function(){
Auth::routes();
}).
I haven't tested this but it should work because Laravel references the routes by their name (e.g. route('login')) which would stay the same.
Alternatively you could just define your own routes instead of using Auth::routes() at all. You can copy the routes from the laravel/ui package and adjust them as needed.
I am using Laravel 5.5 version. I defined my routes in the routes.php file. like this:-
$router->group(['middleware' => 'auth'], function($router) {
$router->resource('/route-name', 'myController#myMethodName');
});
But when I run my application laravel gives error:-
Method [myMethodName#index] does not exist on [App\Http\Controllers\myController].
It is by default put index action after my defined action in the routes.
It is working fine in the laravel 5.3 version. Please solve my problem..
Try this as #devk told in comment:
$router->get('/route-name', 'myController#myMethodName');
By Default resource Request create CRUD requests in routes. For the following methods in Controller.
Index(GET)
Create(GET)
Store(POST)
Show(GET)
edit(GET)
Update(PUT/PATCH)
Delete(DELETE)
You can't pass method name in resource route.
If you want to override any of them. you have to write new one route below the resource Route. Like
Route::get('url','Controller#newMethod');
And Change the method name in Controller with newMethod
For more detail check laravel documents
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'));