I am getting NotFoundHttpException in RouteCollection.php line 161: - php

I am getting this error when I run it at http://localhost/myproject/public/vendor
the following is my routes:
Route::get('vendor', array('as'=>'vendorform','uses' => 'VendorController#create'));
Route::post('vendor', array('as'=>'saveVendor','uses' => 'VendorController#store'));
This is my create method in VendorController
public function create()
{
//
return view('vendor');
}
When I run php artisan route:list the route vendor is not listed
I have tried route:clear in the php artisan but this could not solve the problem.
vendor.blade.php is under /resources/views directory
Please any help. What's challenging me is that some routes configured in the same way works while others cannot work.
Please help.

You should not use public in url you run. You should run http://localhost/myproject/vendor url

Related

Laravel (ver 6) php artisan route:list return "Target class does not exist" error with production environment (worked fine in local environment)

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

I am creating edit page using PHP Laravel 5.8. I have created routes and url, but error 404 not found shows up

I am learning the Laravel by building a job portal app. And I am coding for the company side to edit their post.
Now I could go to url, ex) http://localhost:8000/jobs/23/edit. But on the screen shows me 404|not found error message
This is an screen shot
for edit page, I created views/jobs/edit.blade.php.
Of course, data is clearly inserted in my job table.
I tried to clear all the cache and, executed following commands.
1. composer dump-autoload
2. php artisan clear-compiled
3. php artisan optimize
4. php artisan config:cache
web.php
Route::get('/jobs/{id}/edit', 'JobController#edit')->name('job.edit');
JobController.php
public function edit($id)
{
$jobs = Job::findOrFail($id);
return view('jobs.myjob',compact('jobs'));
}
my-job.blade.php
I have an edit button and following code is a link it has.
{{route('job.edit',[$job->id])}}
My environment is Windows, XAMPP and local MySQL server.
try this way :
Edit Job {{$job->id}}
you can clear route cache by :
php artisan route:clear
update : run following command to clear cache
php artisan config:clear
php artisan cache:clear
I finally could solve this problem.
I changed to a new route.
Route::get('/test-jobs/{id}/edit', 'JobController#edit')->name('test-job.edit');
I created new blade.php like this, views/test-jobs/edit.blade.php
I also changed JobController.php
public function edit($id){
$jobs = Job::findOrFail($id);
return view('test-jobs.edit',compact('jobs'));
}
And finally, my-job.blade.php which has an edit button like this.
<button class="btn btn-dark">Edit</button>
But still, I don't know why it worked.
And also, I think I need another solution. Because in this way, I needed to create another new folder in views.
So if someone knows another solution, please let me know.
Thank you.
The problem is probably in the line return view('jobs.myjob',compact('jobs')); in your JobController.php, it returns the following view: resources/views/jobs/myjob.blade.php (which probably doesn't exist).
try changing the line return view('jobs.myjob',compact('jobs')); to return view('jobs.edit',compact('jobs'));, after the change it refers to resources/views/jobs/edit.blade.php and that should solve your problem.

PHP artisan controller error

I try to make a controller with PHP artisan but when I run command php artisan make:controller TasksController I confront with following error:
In RouteAction.php line 84:
Invalid route action: [App\Http\Controllers\TaskController].
why this error to be occur?
Thanks in Advance.
The error occurs because you're trying to execute TaskController without action. You need to add action to the controller:
Route::get('task', 'TaskController#someAction');
If you don't have a similar route, it means routes are cached with some wrong route. Since Artisan commands do not work, clear this cache manually by deleting this file:
bootstrap/cache/routes.php

NotFoundHttpException in RouteCollection.php when after sync with github desktop

My laravel project is showing this error: NotFoundHttpException in RouteCollection.php when i am trying to sync my project to github using github desktop, except for this route:
Route::get('/', function () {
return view('welcome');
});
but another simple route like following will not work, and return that error.
Route::get('loa', function () {
return view('loa');
});
In route list, using route command: php artisan route:list it says it exists. but it always returns Route not found. I also have tried to use the command dump-auto load or route:clear, but nothing is working.
Run composer update then try again.

Laravel 5 - View [home] not found

I ran composer update and now I'm running into an issue. I'm getting this error when I'm trying to load my home view:
InvalidArgumentException in FileViewFinder.php line 140:
View [home] not found.
Yes, files exists in my directory (resources/views, etc.). Name is home.blade.php.
My controller:
<?php namespace Hulahoop\Http\Controllers;
use Hulahoop\Http\Requests;
use Hulahoop\Http\Controllers\Controller;
use Illuminate\Http\Request;
class HomeController extends Controller {
/**
* Display a listing of the resource.
*
* #return Response
*/
public function index()
{
return view('home');
}
}
Route:
Route::get('/', 'HomeController#index');
This was working fine and it's very basic function. What happened? Running on local homestead FYI.
UPDATE: When I run php artisan serve, I can view the home page view fine (i.e. on http://localhost:8000). But on homestead, no dice. What gives?
There seem to be a problem with vagrant and php artisan config:cache.
If you run php artisan config:clear and then try to open the page - you should see it working fine - just make sure you don't cache it via artisan.
Check out [ vendor/config.php ] it's hard-coded for local development.
You need to give executable permission for the view folder 755

Categories