Laravel 5.5 all routes except home result in 404 not found - laravel-5

Just trying out laravel 5.5 which I installed in cpanel. Only the root route is working:
Route::get('/', function () {
return view('public/content/home-content');
});
Even this isn't working
Route::get('/about', function () {
return view('public/content/about-content');
});
It also work:
www.mydomain/index.php/about
How can I solve this error

Related

Laravel vue-router config for frontend, exclude backend

I using laravel + vuejs
Backend use laravel (/admin)
In routes/web.php
...
Route::get('/{any?}', function () {
return view('welcome');
})->where('any', '^(?!api\/)[\/\w\.\,-]*');
When I run some url
test.com/admin
test.com/admin/users
-> All redirect to welcome layout
How to config to vue-router only run exclude /admin (backend)
Route::get('/{any?}', function () {
return view('welcome');
})->where('any', '^(?!admin).+');
It's just a regex problem, try this

How to exclude routes from route GET

New to laravel so Im trying to do something that doesn't work. I'm building a backend dashboard with login & register page, these 2 pages should have different layouts. How can I do this as the way below is not working. I'm using VUE.
Of course is {any} gonna get all so is there a way to exclude pages from this?
web.php
Route::get('/{any}', function () {
return view('layouts.vue');
})->where('any', '.*');
Route::get('/login', function () {
return view('entry.vue');
})->name('login');
You should add your route on top of route with {any}.
For example:
Route::get('/somewhere', function () {
return view('somewhere');
});
Route::get('/login', function () {
return view('entry.vue');
})->name('login');
Route::get('/{any}', function () {
return view('layouts.vue');
})->where('any', '.*');

How to handle if does not have a "current" tenant?

I'm using Spatie laravel-multitenancy. laravel v8
I'm not defined domain one.localhost and now I'm getting an error. so how to handle the error.
error is
Spatie\Multitenancy\Exceptions\NoCurrentTenant The request expected a
current tenant but none was set. http://one.localhost:8000/
web.php
Route::domain('{tenant}.localhost')->middleware('tenant')->group(function(){
Route::get('/', function ($tenant) {
return $tenant;
// return view('welcome');
});
});
Route::domain('localhost')->group(function(){
Route::get('/', function () {
return view('welcome');
});
});
Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
return view('dashboard');})->name('dashboard');
Hi I am facing the same problem and after Debugging I found that I missed domain in tenants table
please add "one.localhost" in tenants table and everthing will be fine
if you don't have tenants table please run
php artisan vendor:publish --provider="Spatie\Multitenancy\MultitenancyServiceProvider" --tag="multitenancy-migrations"
php artisan migrate --path=database/migrations/landlord
Actually this package also provide Exception Handling if tenant did not exist. You can study more in these links
https://spatie.be/docs/laravel-multitenancy/v2/basic-usage/automatically-determining-the-current-tenant
https://spatie.be/docs/laravel-multitenancy/v2/advanced-usage/ensuring-a-current-tenant-has-been-set
Hi i get same error and i solve it by add the handle exception for NoCurrentTenant
got to Handler.php and try this register function:
$this->reportable(function (NoCurrentTenant $e) {
abort(404);
});

How to add routes in an SPA using Laravel?

I'm building an SPA. In my web.php file I have this:
Route::get('/{any}', function () {
return view('welcome');
})->where('any', '.*');
Which is great, and I'm using Vue-Router for routing.
But I'm trying to add Stripe payments and in a lot of these videos that I've seen or articles that I've read, they often are still working with a few .blade files as well as .vue components.
I want to add a route for a blade file called checkout.blade.php
So now I will have this in web.php:
Route::get('/{any}', function () {
return view('welcome');
})->where('any', '.*');
Route::view('/checkout-now', 'checkout');
The issue is I don't see anything, just a blank white page when I go to this route, I assume it has to do with the first Route, but how do I get around this? How can I see .blade routes in my SPA?
In this case I recommend to keep all your routes before the any route.
Route::view('/checkout-now', 'checkout');
.
.
Route::get('/{any}', function () {
return view('welcome');
})->where('any', '.*'); // Must be at the end
if you just need few route for vue router
$paths = ['vue-path', 'vue-path-id'];
foreach ($paths as $path) {
Route::get($path, function () {
return view('welcome');
});
}
Route::view('/checkout-now', 'checkout');

LARAVEL 5.2 - How to access login page as default page

I just need to know how i can set the login page as default page of my site.
Route::get('/', function () {
return view('welcome');
});
I need something like this:
Route::get('/', function () {
return view('auth.login');
});
It's possible?
Thanks
Yes, it's possible, just put this route before all other routes and this will work.
If you're using standard Laravel 5.2 auth system, you can create this route and use it before all other routes:
Route::get('/', 'Auth\AuthController#getLogin');

Resources