Route/View related issue in Laravel - php

I've encountered a problem while creating simple apps with Laravel on IIS.
When I create a new Laravel application I can see the Laravel welcome page just fine.
If I create another view in the same folder as the welcome.blade.php (test.blade.php for example), and set up the route for that in routes/web.php I can't navigate to that page in browser. EDIT: When I attempt this I get a 404.
My web.php is as follows:
<?php
Route::get('/', function (){
return view('welcome');
});
Route::get('/test', function (){
return view('test');
});
At first I thought that perhaps the project was not reading web.php, but when I run php artisan route:list the test route is listed.
I thought perhaps that my view didn't work, so I renamed it as welcome.blade.php and that loaded up fine. I just seem to be unable to add a route to any view or anonymous function that isn't mapped to welcome.blade.php
I tried adding a static route.php file into the app directory with the same code, but that made no difference to the result.
I'm sure I must be missing something basic, but I can't seem to put my finger on where I've gone wrong. Would massively appreciate any help you might be able to offer. Thank you.

Right I worked out where I went wrong. I hadn't run artisan serve. Very simple.
If you're having this problem, try navigating to your application root in cmd and then try
php artisan serve
Then navigate to your page using that information.
Thank you to everyone who posted, massively appreciated.

You need to install Url Rewrite in your terminal. Then import the .htaccess file located in your project/public folder.
To install Url Rewrite, you need to install Web Platform Installer (WPI). Once installed, open WPI then search for the keyword "Url Rewrite", then install the first item in the result. Once the download is finished, Url Rewrite will be available in your IIS Manager

I think IIS server maybe blocks test url.
IIS server has such features.
Before time, I remember that I used IIS blacklist url feature.
You may check IIS url block feature.

Related

How to access my-domain/admin in laravel?

Route::get('/admin', 'Backend\HomeController#index')->name('admin.home');
is from routes/web.php and it's not working online. It's fine in local
Route::get('/superadmin', 'Backend\HomeController#index')->name('admin.home');
or any name except 'admin' is working online and local.
But I've already used /admin in my project in many places.
That's why I can't use /superadmin.
Please Help.
website backend:
http://ischebazar.com/admin
login:
http://ischebazar.com/admin/login is working.
I can't comment so I need to post an answer for this.
What do you mean by it does not work? Does it show you the laravel 404 page, a server error or a blank page?
If it shows you the laravel 404 page try clearing the route cache: php artisan route:clear.
If it's a blank page, try checking if you have a folder called admin in the document root of the project.
For a server error I can't guess whats wrong but you can provide additional information if this is the case.
Try executing the following command to clear out cache,
php artisan config:cache

laravel route fix needed

I have a laravel project which I run from my local apache server directory.
The link for accessing this project is
www.localhost/project.dev/public/index.php
And I have a navigation menu
After I have set the APP_URL in .env file to
http://localhost/blog.dev/public/index.php/
I get no problems while navigating through the About and Contact pages in the project but when I access the Home page the browser goes to the
http://localhost/
but not to the
http://localhost/blog.dev/public/index.php/
How can I fix it? Here are my routes:
Route::get('/', 'PagesController#getIndex');
Route::get('about', 'PagesController#getAbout');
Route::get('contact', 'PagesController#getContact');
I think the best way is to setup a vhost in apache. if you want to work like this in your .env set the APP_URL= http://localhost/blog.dev/public/
Run php artisan serve in command line. The laravel buil-in server will active. And you will able to access your laravel application using correct url as like http://localhost:8000 try this and let me know if you have any problem.

Laravel 5.3 route not working

I have installed fresh copy of laravel 5.3.
I have the following code in my route/web.php.
Route::get('/', function () {
return view('welcome');
});
Route::get('welcome', function () {
return view('welcome');
});
when i hit localhost/project/public in the browser i can see laravel welcome page.
But when i hit localhost/project/public/welcome then 404 Not Found comes up where i should get the same laravel welcome page.
Am i forgetting something ?
Laravel is case insensitive, so if you created the project with one of these will not find the path.
Has your route file been cached? See what happens when you run:
php artisan route:clear
and try again.
I was having some trouble with this myself, so for anyone having trouble with getting a Laravel route to work:
Make sure your route is defined the correct way by running php artisan route:list Your route should show up, along with the method. (get, post, ...)
Enable mod_rewrite from the Apache settings so Laravel can map /uri to whatever you like.
Modify the .htaccess or Apache settings to allow url overrides: AllowOverride All If you are working on something like localhost/~username/yourproject, also check the username.conf file in /private/etc/apache2.
I'm not an expert in Apache settings, so feel free to correct or elaborate where needed.
goto htaccess in your laravel folder
after ( RewriteEngine On ) add this
RewriteBase /yourlaravel project name/public
example:
RewriteBase /laravel/public

File::exists() in Laravel 4.x not working when the project is served

I'm developing a project in Laravel 4.x. I'm currently using File::exists() function on the routes.php as an error trap, the code looks like this:
Route::get('/', function() {
if(File::exists("settings/config.xml") {
// do something with the config.
// then go to the site.
}
else {
// cannot proceed anymore.
}
});
I'm developing my project on a WAMP Server. Everything is fine and it returns true until I served it (php artisan serve --port=8080). It now cannot find the file I was looking for! I found an alternative for it to work -virtual hosting, but what I need is the method to check the file exists when it is served.
I've tried to type on the URL address bar the exact path, and it can find the file (the browser downloaded it, in fact): localhost:8080/settings/config.xml
Is there something wrong with my code? Thanks for helping.
EDITED:
When I said everything is fine until I served it, I am referring on running my project through this URL: localhost/project/public
Maybe add slash root to the path.
like this: File::exists("/settings/config.xml")

Laravel base route errors "NotFoundHttpException"

I'm too newbie to Laravel...I have written this route to echo "Hello World", but It errors NotFoundHttpException
This is my routes.php (no other code is in the file but the following):
Route::get('/', function(){
return "HELLO WORLD";
});
I have also enable mode_rewrite, and also set AlloOverride to 'all' in apache module.
This is also the URL is use to access the page:
http://localhost/laravel/public/mostafa
Do:
php artisan serve
Use that URL to visit your website.
You will see that you get some output like:
Laravel development server started on http://localhost:8000
When you have no clue what Artisan is take a look at this;
http://laravel.com/docs/artisan
Navigate into your project directory with your command prompt and run there the serve command from above.
Example:
Sometimes the default .htaccess file located in public folder doesn't work in apache. Try altering the .htacess as mentioned here. Alternatively renaming your laravel project folder would work especially in XAMPP.
Some other frameworks treat route definitions as relative to the project web root so a path defined as /foo/bar will match http://example.com/additional/levels/laravel/public/foo/bar and will work without changes even if you move the project tree somewhere else in your public web hierarchy. Laravel, however, considers routes as absolute paths so /foo/bar will only match http://example.com/foo/bar.
The simplest solution is probably to move your code into a separate virtual host and point its document root to laravel/public/. (In this case it seems that's actually the intended set-up.)
(I suppose there's a way to make the framework assume an implicit prefix but I've only been using Laravel for 10 minutes.)

Categories