I've been laraveling for 5 months now but I reformatted ubuntu and installed Laravel, this time, it's Laravel 7 instead of Laravel 6. My problem is simple routing giving an error. It's so dead simple you might think I'm a stupid beginner.
In my Web.php
Route::get('/about', function () {
return view('welcome');
});
Route::get('/', function () {
return view('welcome');
});
I also tried using a controller that returns a view and just a simple "string" in Web.php
Route::get('/about', 'UserController#index');
Typing http://localhost/about in the address bar in chrome causes 404 error.
As you can see, there should be no problem returning the same view('welcome'), even if I return a simple return "TEST";, results are the same.
I tried downgrading to Laravel 6 by deleting vendor, changing the Laravel v6 in composer.json and running composer install but still the same, so I think it's not the version.
This has never happened to me before even when I first started with Laravel 6 five months ago and it's a totally fresh project.
enable rewrite_mode of Apache server and restart Apache server it will solve the issue.
Run server with php artisan serve
and then try http://localhost:8000/about hope it will fix your problem
OR
Simply use http://localhost/project/about
Related
I'm using laravel 6 for BE and vuejs for FE. Wtih my local environment ( built on xampp server ), everything was fine. But, when I deployed the app to the server(Lamp server with ubuntu 18.04), I got the following error when I tried to run "php artisan route:list".
Illuminate\Contracts\Container\BindingResolutionException : Target class [App\Http\Controllers\Masterdata\CountryController] does not exist.
at /var/www/html/performance.goautobot.chat/public_html/performance/vendor/laravel/framework/src/Illuminate/Container/Container.php:806
try {
$reflector = new ReflectionClass($concrete);
} catch (ReflectionException $e) {
throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
}
And some APIs are not working. The weird part is both "Roles" and "Countries" have exactly the same structure as the following but only apis related to "Roles" are working got "BindingResolutionException" error when I tried with Postman.
Route::group(['middleware' => 'auth:api'], function () {
// Countries
Route::get('masterdata/countries', 'Masterdata\CountryController#index');
// Roles
Route::get('masterdata/roles', 'Masterdata\RoleController#index');
}
I tried to solve it by running the commands like "composer dump-autoload" and "php artisan config:cache" but it didn't fix the problem. Also, tried to remove the project folder and made a new installation and deployment.
Please let me know how to fix the issue. Thank you so much in advance.
I had a similar issue with HomeController, then I checked the routes in the web.php file,
I found it was like the following
Route::get('/', 'HomeController#index');
Then I changed this to the following according to the directory where the Homecontoller resides
Route::get('/', 'App\Http\Controllers\HomeController#index');
after that, it worked correctly.
So Please check your controller directory,
if your controller directory is "App\Http\Controllers\Masterdata\CountryController" then add this in the route. it will be like following
Route::get('/', 'App\Http\Controllers\Masterdata\CountryController');
I tried to explain according to my scenario,
Please let me know if this helps and please pardon me if I have got something wrong
UPDATE: My issue had nothing to do with Laravel sessions, it was my Service Worker that was causing sessions to mess up! Although I still don't understand why the service worker was fine for a different hostname with the same code, but after disabling it sessions work fine now! Will leave this here in case anyone else stumbles upon session issues and don't immediately think about any service workers they have.
Since migrating to Laravel 5.2 I've been having session persistence problem with Session::flash and subsequent Session::keep usage.
I know I'm supposed to use the web middleware group, and I am. But that isn't solving my problem. Please see below:
app/Http/Kernel.php
protected $middlewareGroups = [
'web' => [
...
\Illuminate\Session\Middleware\StartSession::class,
]
];
app/Http/routes.php
Route::get('test', function(Request $request) {
$request->session()->flash('test_flash', "Some value");
return redirect('/flashed');
});
Route::get('flashed', function(Request $request) {
$request->session()->reflash();
return redirect('/flash-kept');
});
Route::get('flash-kept', function(Request $request) {
var_dump($request->session()->get('test_flash'));
});
The first time I hit /test it redirects to /flash-kept with value of test_flash as NULL - but second time I hit it, again it redirects but this time with correct value! And this is consistent in that every time I load any other page, then load /test it doesn't keep the flash message, only second time hitting it does.
Can someone see anything wrong??
This is happening on a Debian machine running PHP 5.6.30, very interestingly I cannot replicate this behaviour on my local machine, macOS running PHP 7.1 - but I don't think it's PHP version either as I quickly tried downgrading my local machine to use PHP 5.6 and I still couldn't re-create the issue! I've been staring at this for the last few hours, cannot see anything wrong!
I've picked up a project that was developed using Laravel 4.2. I've deployed it to my testing server (a Bitnami LAMP) and everything works as it's supposed to. HOWEVER, new routes that I create don't work, getting the error NotFoundHttpException.
I've gone through a few recommendations, but nothing has been successful thus far.
Any thoughts or ideas??
Thanks!
--
Just to clarify, any NEW route throws the same Not Found error. Even the simplest one like:
Route::get('test', function(){
return "This is a test";
});
It seems like Laravel is only serving an old version of the Routes.php, is this even possible???
Resolved this by recreating the project using Laravel 5 instead.
When I left work yesterday the routeing worked perfectly. I haven't touched it since, and the only thing I did after I tested the site (and it worked) was make a new model and migration using php artisan make:model.
When I came in to work, about 35 minuets ago, poof. site doesn't work. the routes work with a get method (Route::get('/', 'blahContoller#index') but fails on ALL the Route::post methods. I'm stumped. Going back to laravel 5 after this project, 5.1 is unbelievably broken and worse then 5.0 and has casued me no end of problems that actually wastes more time then laravel is supposed to save.
The error I get:
NotFoundHttpException in RouteCollection.php line 143
my routes:
Route::get('/', 'TurboController#index');
Route::post('checkout', 'TurboController#checkout');
Route::post('securePayment', 'TurboController#securePayment');
Route::get('thankYou', function(){
return view('thankYou');
});
I dont understand, I havent touched the route file since yesterday at 9:00am and worked up until I tested it today.
I HAVE TRYED DUMPAUTOLOAD before you ask ;)
try to run these in terminal
php artisan clear-compiled, php artisan cache:clear, php artisan route:clear
I googled the matter and there are many who've had this issue, but each had his own very unique case, and at the end nothing I read helped me.
I just finished installing Laravel with xampp, hopefully properly. Apache and MySQL are running.
I'm starting with the very first tutorial:
http://laravel.com/docs/4.2/quick#routing
My app root is:
http://localhost/Laravel/tests/app/
The hello.php file is working for me, I even tested some php code (plain not laravel) and it worked:
http://localhost/Laravel/tests/app/views/hello.php
As the tutorial instructed, I added in app/routes.php:
Route::get('users', function()
{
return 'Users!';
});
but when I try to access
http://localhost/Laravel/tests/app/views/users
I get "Object not found!" while I should be getting the text "Users!"
This is not route correct, test with: http://localhot/Laravel/tests/public/users