Passing more than one parameters in route messes up my view - laravel

I am a beginner to laravel. When I pass more than one parameter through the route my view gets messed up. For example when my route is {{URL/product}}. It is ok, but when try it the other way i.e {{URL/product/anything}}, the view is messed up.
[This is the correct view][1]
These are my routes :
(Working)
Route::get('/addproduct' , 'AdminController#add_product')->name('add_product');1
(not working)
Route::get('/add/product' , 'AdminController#add_product')->name('add_product');This one is not working
I haven't changed anything but my web.php file.

This is probably because of how you are linking to your assets. You are most likely using relative URLs. Try using one of the URL helpers to generate absolute URLs for you.
href="{{ asset('css/somefile.css') }}"
Laravel 7.x Docs - Helpers - URLs asset

Related

Laravel subdomain route problame

I am working on a subdomain system on laravel.
suppose my main domain name is: test.test
and my subdomain name is: subdomain.test.test
Now, the problem is, when I use the main domain route in sub-domain blade file like:
Profile
then, it should generate links like test.test/profile
but, it's generating links with subdomain like: subdomain.test.test/profile
Now, How can I solve this problame?
An alternative would be to use relative path instead of absolute using route() helper third parameter.
Profile
I recommend you to use Spatie Multitenancy, when i do route('home'), he return back the url with the actual domain.

Links in Laravel

I'm am just starting out in Laravel, been using codeIgniter for years. Very quick question as the Laravel documentation does not seem to address this. Do all links in your blade file have to have defined route in the routes files. In codeigniter it was generally /controller/function in your links but it seems to me in Laravel all links have to be defined in routes file...
No, they do not have to be defined.
There's nothing prohibiting you from using <a href='/whatever/you/want'> -- That said, it's generally better to use defined routes and reference them by name, that way, if you ever change the actual structures, the route('name'); will automatically resolve to the new structure.
You can use
{{ url('/what/you/want') }}
https://stackoverflow.com/a/42270157/4173464
Look at https://laravel.com/docs/7.x/urls too
You must define all your routes in Laravel.

Laravel - Root Url suffix and route prefix inconsistency

We have a test site with laravel 4, which is on a subfolder on the server. So it is on thedomain/sitename. This have caused big challenges with routing. The routes became wrong, like: thedomain/about instead of thedomain/oursite/about.
I added a Url root suffix'oursite' by using the Illuminate\Routing\UrlGenerator (following this suggestion).
All urls in the templates became correct, but they don't match anything in routes.php which still treats it without the suffix.
I tried adding a route prefix . Now the urls typed into the address bar worked. But all the urls in the templates became wrong, for instance thedomain/oursite/oursite/about.
So this seems inconsistent - why is the root Url suffix added to all the routes when they are echoed in the templates (like <a href="{{ route('about'); }} ) but they are interpreted without the suffix in routes.php!?
How can I get around that? I thought I was close to solving this. Or could I use route filter to redirect on every link?
Alternative solution: maybe use subdomain like sitename.thedomain.com instead of subfolder. If your server provider not support subdomains, change provider :P

Change Base URL in Laravel 5.5

I 'm trying to change the base URL http://myscreenclass.com/ to http://myscreenclass.com/home. I changed the .env file and updated the config/app.php file as well. I tried to solve the issue many different ways, but nothing happens.
How can I change the URL?
I am trying to change base URL http://myscreenclass.com/ to http://myscreenclass.com/home
May I suggest reading up on routing with Laravel? You can achieve this by adding this to your web routes file.
Route::redirect('/', '/home');

Redirecting to a Laravel Spark Settings Page

In Laravel Spark, settings pages have URLs that look like this
http://app.dev/settings#/security
Is there a way, via Laravel's PHP code (from a controller action) to redirect to these URLs that doesn't involve manually adding the # portion to the URL via string concatenation?
In other works, I know I can do this
return redirect(
route('settings') . '#/security'
);
but it feels sort of gross. I guess another way of asking this question is, is there a built-in way to generate route based URLs in laravel that include the # portion of a URL.

Resources