0

I am trying to create a view with four inputs which all enter that data into an sql database (using Laragon).

When I try click on the submit button I get an error saying "Target class [BikeController] does not exist."

Here is my controller:

<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class BikeController extends Controller { function add(Request $req) { print_r($req->input()); } } 

Here is my routes

<?php use Illuminate\Support\Facades\Route; use \app\Http\Controllers\BikeController; Route::view('/add', 'addView'); Route::post('/add', 'BikeController@add'); Route::get('/', function (){ return view('bikesView'); }); Route::get('/delete', function (){ return view('deleteView'); }); Route::get('/edit', function (){ return view('editView'); }); 

Link to a pic of my file structure

Currently I'm just trying to print out the data input on the screen but will eventually link it to mysql.

4
  • please share your actual code, not pictures of your code. Commented May 2, 2021 at 7:12
  • Please share the directory structure. Your controller may have a different path than namespace Commented May 2, 2021 at 7:15
  • Share your actual code and also the blade, where you send your POST. Commented May 2, 2021 at 7:16
  • On your controller, add this on the top use App\Http\Controllers\Controller: Commented May 2, 2021 at 8:01

3 Answers 3

1
=> Open App\Providers\RouteServiceProvider.php and uncomment this line protected $namespace = 'App\\Http\\Controllers'; 
Sign up to request clarification or add additional context in comments.

7 Comments

Please edit your answer to contain more details, such that others can learn from it
If you create a new Laravel 8 project,there is no namespace prefix being applied to your route groups that your routes are loaded into. This causes en error that says Target class does not exist.
Please edit your answer to contain all relevant information
Though there is a mention of a $namespace property to be set on your RouteServiceProvider in the Release notes and commented in your RouteServiceProvider this does not have any effect on your routes. It is currently only for adding a namespace prefix for generating URLs to actions. So you can set this variable, but it by itself won't add these namespace prefixes, you would still have to make sure you would be using this variable when adding the namespace to the route groups.
Please add all clarification to your answer by editing it. Don't use the comment section for such important explanation
|
0

in your controller change this:

namespace App\Http\Controllers\BikeController; 

to:

namespace App\Http\Controllers; 

in namespace you just mention the path to the file

1 Comment

Tried this and didn't work :(
0

First check your controller if there is any error solve it, then check your web.php, if there is not an error and after that run those artisan commands for clearing the cache.

Controller:

<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Controllers\Controller; class BikeController extends Controller { function add(Request $req) { print_r($req->input()); } } 

web.php

<?php use Illuminate\Support\Facades\Route; Route::view('/add', 'addView'); Route::post('/add', 'BikeController@add'); ?> 

Run the below artisan command:

//---Remove Routes Cache php artisan route:clear; //---Flush the application cache php artisan cache:clear; 

And if you want to regenerates the list of all your project classes run this composer command:

composer dump-autoload; 

2 Comments

Tried this and didn't work :(
Please add some explanation to your answer such that others can learn from it. Why should clearing some caches help in this situation?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.