PHP Laravel route after installation - php

I installed new laravel project("Starter") and want to view the 'welcome' page by putting this URL.
http://localhost/starter/
The page ran fine when the route is the following.
Route::get('/', function () {
return view('welcome');
});
However, when I write any thing after the (/)...
Route::get('/test', function () {
return view('welcome');
});
And view it by URL:
http://localhost/starter/test
The page doesn't work and shows...
404
Not Found
Any ideas?

(s) in word (starter) in the URL, shoud be UpperCase (Starter) as the name of Laravel project

Related

The get in laravel doesn't find any page

I am very a beginner in Laravel
I launch my laravel project on localhost
<http://localhost/ecommerce/public/>
Route::get('/', function () {
return view('welcome');
});
this give me the welcome page
But I want to add about page but it always say "404 Not found"
and that's my code:
Route::get('/about', function () {
return view('about');
});
I made a file in views and called it "about.blade.php"
when I type to view about like this :
Route::get('/', function () {
return view('about');
});
and remove the welcome get, it works and give the about page
but when I put it in get "/about" it always doesn't work, even if I just type "string"
why it can't recognize get "/about"?
You should run the project with php artisan serve in terminal or in the server you have to change document root and remove the public in URL
the reason is the extra public in your url

how to make login page as first page laravel 8

i am trying to make the login page as a start page on laravel 8 i tried to delete welcome page to remplace it with login blade and get and i cant get any results
Route::get('/', function () {
return view('welcome');
});
something like :
Route::get('/', function () {
return view('auth.login');
});
and this is the middleware
Route::group(['prefix'=>'directeur','middleware'=>['isDirecteur','auth']], function(){
Route::get('dashboard',[DirecteurController::class,'index'])->name('directeur.dashboard');
Route::get('rapport',[DirecteurController::class,'rapport'])->name('directeur.rapport');
Route::get('detail/{id}',[DirecteurController::class,'detail'])->name('directeur.details');
});
any suggestions ??
first declare your route middleware, then use Route::view for rendering blade file. Based on docs
// Your middleware Route
...
//
Route::view('/', 'auth.login');

Change the route in Aimeos Laravel

I am using Aimeos e-commerce on a Laravel site, I want to change the store route to /shop but I get an the browser doesn't open a page I do it as follows
Route::get('/shop', function () {
return redirect('shop');
})->name('shop');
but when I make on "/" main page it displays perfectly. How to change its route?
Use this in your route/web.php file:
Route::get('/', function () {
return redirect('shop');
});
See https://github.com/aimeos/aimeos/blob/master/routes/web.php

Redirect All URL's With A Particular Pathname To A Certain View - LARAVEL

Okay i'm running two react projects using laravel, a website and an admin section. I want both apps rendered on separate pages because their css would clash.
So in my web.php i have this Route::view('/{path?}', 'app');, but this redirects all my routes to my app.blade.php view.
I'm justing wondering if i can have a route that redirects any route with a specific pathname, let's say: mydomainname.com/admin to my admin.blade.php. Then every other route goes to my app.blade.php.
You can use Route::prefix like this:
Route::prefix('admin')->group(function () {
Route::get('users', function () {
// Matches The "/admin/users" URL
});
});
Okay i was able to pull it off. Erkan Ozkok's answer gave me a hint.
Route::prefix('admin')->group(function () {
Route::view('/{path?}', 'admin');
});
Route::any('{query}',
function() { return view('app'); })
->where('query', '.*');

How should I set up Laravel routes?

I'm a beginner in Laravel and I'm having some difficulties with routes. Actually, I'm having difficulties with a lot of things in Laravel, some of which I've managed to wrap my head around (such as migrations, seeding and authentication) but this is one of the most basic ones.
I've been creating routes based on the one that comes with Laravel. However, after much googling, something seems off. I'm not sure this is how it should be done.
My current web.php file looks like this:
Route::get('/', function () {
return view('pages.home');
});
Route::get('/about', function () {
return view('pages.about');
});
Route::get('/login', function () {
return view('login');
});
Route::get('/student', function () {
return view('profiles.student');
});
Route::get('/professor', function () {
return view('profiles.prof');
});
Route::get('/profadmin', function () {
return view('profiles.profadmin');
});
Route::get('/ident', function () {
return view('pages.ident');
});
// Authentication
Auth::routes();
Route::post('/login', function () {
return view('pages.ident');
});
Route::get('logout', 'Auth\LoginController#logout');
// Route::get('/home', 'HomeController#index')->name('home');
// Route::get('/ident', 'HomeController#ident')->name('ident');
//
// Route::get('/aluno', 'HomeController#aluno')->name('aluno');
//
// Route::get('/ident', 'HomeController#ident')->name('ident');
Also, certain pages should only be viewed by authenticated users and I'm having a hard time understanding how exactly that is done and how the routes should reflect that.
I'm sorry if this is simple stuff, but this is my first time using a PHP framework. Any help will be much appreciated.
lets suppose you want to protect the about route
then in the web.php file, replace your about route with this:
Route::get('/about', function () {
return view('pages.about');
})->middleware('auth');
now anyone hits /about and not logged in, it will be redirected to /login
if you want to know more about authentication, Laravel documentation really the best place for you:
https://laravel.com/docs/5.5/authentication#protecting-routes
First if you are beginner you should read Laravel documentation & Laracasts
In your routes you trying to show only views
Route::get('/about', function () {
return view('pages.about');
});
In Laravel 5.6 you can do it like this
Route::view('/about', 'viewName');

Categories