I have a check in my code that doesn't work in production mode.
In local mode, the code returns the prefix of a route with a forward slash prepended but in production, it doesn't.
My route is defined without a forward slash in the prefix.
Any ideas why this would be returning different results?
Route::current()->getPrefix() == '/xxx'
Route::name('business.')
->prefix('business')
->group(function() {
Route::get('/', 'App\Http\Livewire\Marketing\Business\Index')->name('index');
});
Related
$routes->get('MATCH ANYTHING WHICH STARTS WITH sell-', 'Home::navigator/$1');
I want to match any URI which starts with "sell-" without the quotes and redirect to the Home controller navigator method.
For instance, /sell-my-car should be redirected. /sell should not be redirected.
How do I accomplish it?
You can use regex to match a desired uri, like:
$routes->get('(^sell-.*)', 'Home::navigator/$1');
This will match everything starting with "sell-", but not "sell".
More on regex:
https://www.regular-expressions.info/
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.
I am trying to pass any full url in as parameter to route, but the slash seems to mess everything up. If a route is passed in encoded, the route seems to decode it, is there a way to stop this or encode the url again at route level?
Route::get('add/{title?}/{url?}', 'HomeController#add')->name('add');
also i have tired
Route::get('add/{title?}/{url?}', 'HomeController#add_')->where('url', '(.*)')->name('add_popup');
but if it comes across question mark in the url it will drop anything after the question mark.
Check this out
Route::get("url/{url}", function($url) {
return $url;
})->where('url', '.*');
Example: http://myapp.test/url/http://try.me.com prints
http://try.me.com
I would recommend Jeunes answer, however if you still want a route parameter you could do a base64 encode/decode. This will not make for a pretty url though.
JS
btoa("http://someurl.test")
PHP
Route::get('url/{url}', function ($url) {
return base64_decode($url);
});
I want to serve the swagger-ui using gorilla/mux and http.FileServer.
This is the routing that works so far:
router := mux.NewRouter()
router.PathPrefix("/swagger-ui/").Handler(http.StripPrefix("/swagger-ui/",
http.FileServer(http.Dir("swagger-ui/"))))
http.ListenAndServe(":8080", router)
The problem is: only a GET /swagger-ui/ returns the swagger page.
When I do (what most users also expect) a GET /swagger-ui without trailing slash I get a 404.
How can this be solved?
You have probably found the answer as the question is nearly two years old, but I will write the answer here so that anybody who comes across this question can see it.
You just need to define your gorilla router as:
router := mux.NewRouter().StrictSlash(true)
StrictSlash func(value bool) *Router StrictSlash defines the trailing
slash behavior for new routes. The initial value is false.
When true, if the route path is "/path/", accessing "/path" will
perform a redirect to the former and vice versa. In other words, your
application will always see the path as specified in the route.
When false, if the route path is "/path", accessing "/path/" will not
match this route and vice versa.
The re-direct is a HTTP 301 (Moved Permanently). Note that when this
is set for routes with a non-idempotent method (e.g. POST, PUT), the
subsequent re-directed request will be made as a GET by most clients.
Use middleware or client settings to modify this behaviour as needed.
Special case: when a route sets a path prefix using the PathPrefix()
method, strict slash is ignored for that route because the redirect
behavior can't be determined from a prefix alone. However, any
subrouters created from that route inherit the original StrictSlash
setting.
Hello everyone I just installed laravel4 and spend two days trying to make the first step. Now I made it but I'm confused about the Route::get() function and his paremeters.
I installe laravel directly in
/opt/lampp/htdocs/laravel
then follow tutorial to create file
userform.php
into app/views, then add following codes into routes.php
Route::get('userform', function()
{
return View::make('userform');
});
. Then I go to
/localhost/laravel/public
to see welcome page, and
/localhost/laravel/public/userform
to see the form defined in the view/userform.php.
Q1: According to chrome dev tools, i see in the html page, the form action is
http://localhost/laravel/public/userform
but there is nothing under public but
index.php, favicon.ico packages robots.txt
Q2: for
Route::get('userform', function()
{
return View::make('userform');
});
what is the first "userform" represent?? according the official tutorial, it's supposed to be url, but what is the former part?
for this line
return View::make('userform')
I guess "userform" referes to the file /app/views/userform.php, right?
The .htaccess file in the public directory is responsible for funnelling all incoming requests through the index.php file. This allows Laravel to grab the URI and match it to the route you defined and eventually return to you the view you made.
So you request localhost/laravel/public/userform, the request is funnelled through index.php and Laravel is booted. Laravel picks off the userform part of the URI and matches it against your defined routes. It finds the route you defined and fires it and returns the response.
You're spot on with what you were thinking with your second question as well. When you call View::make the first argument is the name of the view you want to "make". If you named your view app/views/forms/user.php then you would return it like so in your route:
return View::make('forms.user');
Or you could use a slash:
return View::make('forms/user');