Error connecting to a defined route in Laravel 5.6 - laravel

I've defined my route in api.php but when I try to connect this route through postman it throws the following error.
The specified URL cannot be found
Here is my route in api.php.
Route::put("certification/{certification-id}/applications/{application}/apply",'MyController#update');
I've checked the ip address and other path variables. Everything is fine but still getting this error.

Swap the - to a _ in {certification-id}
https://laravel.com/docs/5.6/routing
Route parameters are always encased within {} braces and should consist of alphabetic characters, and may not contain a - character. Instead of using the - character, use an underscore (_). Route parameters are injected into route callbacks / controllers based on their order - the names of the callback / controller arguments do not matter.

You should check the port where the localhost is configured to run. If you are using apache, you can check this in httpd.conf file near line number 50.
And make sure you have used php artisan serve as written in here.

Related

How to pass file path with '/' to route laravel?

How can we pass file path to route like this,
<a href={{route('route.name',['path'=>'uploads/xyx/'.$id.'/'.$attachment_name])}}>download</a>
However, I would like this to hit
Route::get('download/{path},'Controller')->name('route.name')
When I hit this route my url got transformed somehow like this -> download/uploads/44/filename which is causing not found exception!
I want to pass the path as a parameter, where slashes should have to be ignored! so that I can get full path in my controller!
As per the documentation you can do this:
"The Laravel routing component allows all characters except /. You must explicitly allow / to be part of your placeholder using a where condition regular expression"
Route::get('download/{path}', ...)->where('path', '.*');
Laravel 7.x Docs - Routing - Parameters - Encoding Forward Slashes
use get parameter remove {path}
Route::get('download,'Controller')->name('route.name')
in blade
<a href={{route('route.name',['path'=>'uploads/xyx/'.$id.'/'.$attachment_name])}}>download</a>
this will generate url like route.name?path=download/uploads/44/filename
still u will get data in controller like $request->path

Broken route in Laravel depending on where it's defined in the file

I have those routes defined in my routes/web.php :
Route::get('references/', 'referenceController#index')
Route::get('references/{reference}', 'referenceController#show')
Route::get('references/create', 'referenceController#create')
Like that, the references/create route goes to a 404 page.
If I put this route one line before, everything works fine :
Route::get('references/', 'referenceController#index')
Route::get('references/create', 'referenceController#create')
Route::get('references/{reference}', 'referenceController#show')
Then it is obviously because of the {reference} part in my route, right? But as I wanted to filter the reference perfectly, I've put a pattern in RouteServiceProvider.php. This pattern should check that my reference is a well-formed UUID :
Route::pattern('reference', '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{10}');
Miles away from the word "create", which doesn't match the pattern.
Do you know why my route is going to a 404 page depending on its position in the file?
This is how Laravel is supposed to work. It isn't very clear in the documentation though I'll admit.
Supplementing Resource Controllers
If you need to add additional
routes to a resource controller beyond the default set of resource
routes, you should define those routes before your call to
Route::resource; otherwise, the routes defined by the resource method
may unintentionally take precedence over your supplemental routes:
Route::get('photos/popular', 'PhotoController#method');
Route::resource('photos', 'PhotoController');
This is also true if you are defining non-resource routes as you noted in your example. This is because it will try to pass "create" as the id of the reference parameter in the route which of course is not valid.
Rule of Thumb
When defining routes that have the same number of url segments, always define the route that does not have a parameter variable first. The routes file will go top-down and find the first route that matches the current request.

Redirects to same action from different urls in laravel 5.2

I am using Laravel 5.2.
I am passing parameters via two urls. But it always goes to the first route only.
code in my routes.php is as follows:
Route::get('{department}', 'settings#load_department_settings')->middleware('auth');
Route::get('{id}', 'settings#load_staff')->middleware('auth');
Anchor tags in view is as follows:
<td>{{$staff->name}}</td>
<td>{{$staff->deptname}}</td>
The issue is it always uses 'settings#load_department_settings'. How could i use 'settings#load_staff' when clicking on staff name?
It is always going to use the {department} route because that is matching anything on the root / slash. You need tto dive at least one of them unique prefixes. For example:
Route::get('department/{department}', 'settings#load_department_settings')->middleware('auth');
Route::get('staff/{id}', 'settings#load_staff')->middleware('auth');
Then
<td>{{$staff->name}}</td>
<td>{{$staff->deptname}}</td>

Routing with slug and id with dash separated?

router->get('{slug}-{id}', 'Controller#method');
router->get('{otherSomething}', 'Controller#method2');
this is my routing and first line doesn't work. how to fix it? my software specification does not allow use slash (/) instead dash (-) in first routing.
for router below samples have the same mask
site.com/slug-name-and-sth-100
site.com/other-something
Assuming your other-something doesn't end with number, you can use Regular Expression Constraints , for example you can define route with id like this:
$router->get('{slug}-{id}', 'Controller#method')->where('id','[0-9]+');
and now it should work. However you need to remember to put this route before the route:
$router->get('{otherSomething}', 'Controller#method2');
otherwise it won't work.
EDIT
In case both urls can have same format, you should remove {slug}-{id} route completely and direct all the traffic for {otherSomething} into one method (method2 in your case).
Now you should parse the $otherSomething variable and decide what you should do:
either you decide it's format {slug}-{id} na you can now run service for this
either you will run other service for other cases

Laravel 4 routing: Cannot use variable name more than once

I'm having an issue with Laravel 4 routing. I am trying to create two sets of routes:
domain.com/meetings/aa, al-anon, etc.
domain.com/meetings/day/sun, mon, tue, etc.
Here is what I am specifying in my routes file:
Route::resource('meetings/day/{dayName}', 'Meetings_DayController');
Route::resource('meetings/{fellowshipName}', 'Meetings_MeetingController');
I need to be able to pass variables to my resourceful controllers. But I am getting this kind of an error, no matter what order I put the routes in:
Route pattern "/meetings/fellowship/{fellowshipName}/{{fellowshipName}}" cannot
reference variable name "fellowshipName" more than once.
Not only that, but those two routes cause other, undeclared routes to give the same error. My 404 route doesn't kick in for some reason. Ideas, anyone? I've tried everything I can think of. If I could match a three-letter string with the day controller route, that would work, but I can't figure out the regex for a three-letter string in Laravel. \w{3} doesn't work.
You are using Route::resource incorrectly. You can't (and should not) pass a variable to a resource controller. Instead You will need to declare a new route with the verb you need and the parameter. Route::resource only creates several pre-handled routes for you for quick CRUD RESTful access
See the answer to similar situation here: https://stackoverflow.com/a/19608572/385402

Resources