i got some error in php 8.2.0 laravel 10.0.0 . Invalid route action: [App\Http\Controllers\ControllerRifan] - php

already try different way, still not working with different error
anyone can help?
I just learn how to use laravel route and controller,

According to the Laravel routing documentation,
You have to pass the route action as an array:
Route::get('/', [ControllerRifan::class, 'index']);

You should make route like this
Route::get('/home', [HomeController::class, 'index']);

//Step 1
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class HomeController extends Controller
{
//
public function index(){
dd('stop');
}
}
// Step 2
<?php
use Illuminate\Support\Facades\Route;
// import controller here
use App\Http\Controllers\HomeController;
Route::get('/', [HomeController::class, 'index']);

Follow the instruction step by step it will work !!
enter image description here

Related

Target class controller [controllerName] not found in Laravel 8

When I hit my register route using Postman, it gave me the following error:
My api.php route:
Route::get('register', 'Api\RegisterController#register');
Here is my controller:
In the official Laravel 8 upgrade guide, you can see that controllers are no longer namespaced by default. This hinders the automatic class resolution with 'Controller#method' syntax.
See https://laravel.com/docs/8.x/upgrade#automatic-controller-namespace-prefixing
The new way of registering routes is to use the following syntax:
// routes/api.php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\RegisterController;
Route::get('register', [RegisterController::class, 'register');
You can also adapt your RouteServiceProvider.php file to "re-enable" the old way to auto-load your controllers using the correct namespace with # syntax:
// App/Providers/RouteServiceProvider.php
public function boot()
{
// ...
Route::prefix('api')
->middleware('api')
->namespace('App\Http\Controllers') // put your namespace here
->group(base_path('routes/api.php'));
// ...
}
It should be changed to:
Route::get('register', [RegisterController::class, 'register']);
first, in the route add the controller name.
use App\Http\Controllers\RegisterController;
In the route use like this way
Route::get('register', [RegisterController::class, 'register']);

Laravel - Not Found - The requested resource /control was not found on this server

Hi everyone I need a solution with laravel project when I try open backend admin with /control its giving me an error "Not Found - The requested resource /control was not found on this server."
When I change the name "/control" to anything like "/control5" or something its working fine but the problem is I use /control at views and other! I am new to laravel I didn't know what the problem was? please help me out with this!
Web.php
Auth::routes();
Route::get('/about', [App\Http\Controllers\AboutController::class,'about']);
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/', [App\Http\Controllers\HomePageController::class,'index']);
Route::get('/listing', [App\Http\Controllers\ListingPageController::class,'index']);
Route::get('/details', [App\Http\Controllers\DetailsPageController::class,'index']);
Route::group(['prefix' => 'control','middleware' => 'auth'],function(){
Route::get('/', [App\Http\Controllers\Control\DashboardController::class,'index'])->name('control');
//Pages
Route::get('/pages', [App\Http\Controllers\Control\PagesController::class,'index']);
Route::get('/pages/add', [App\Http\Controllers\Control\PagesController::class,'create']);
Route::get('/pages/edit', [App\Http\Controllers\Control\PagesController::class,'edit']);
});
DashboardController
namespace App\Http\Controllers\Control;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class DashboardController extends Controller
{
public function index(){
return view('control.dashboard');
}
}
Because, you have a folder named control on /public folder. That error occurs when you create a folder in the public folder with the same name as your route so please change the name of the folder you have put in the public folder so that it has a different name from your route this will probably solve your error

Attribute [livewire] does not exist

I am having trouble to run my code on Laravel 8 routing with laravel-livewire.
The class is within Livewire\LandingPage.
The error I'm getting is
Attribute [livewire] does not exist
Here are my routes
<?php
use Illuminate\Support\Facades\Route;
Route::livewire('/' , 'LandingPage');
Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
return view('dashboard');
})->name('dashboard');
If you are using a recent install of Laravel 8, you will have Livewire V2. In this version, Route::livewire()has been removed. Instead, you specify a normal get() route, with the action being the Livewire component class.
Route::get('/' , App\Http\Livewire\LandingPage::class);
If you use livewire v1.x please use this annotation :
//(livewire v1.x)
Route::livewire('/post', 'LandingPage');
If you are using livewire v2.0 please use this one :
//(livewire v2.x)
Route::get('/post', \App\Http\Livewire\LandingPage::class);
From the error it appears you do not have the auth system setup:
Route::group(['middleware' => 'auth'], function () {
// Only with LiveWire v1
//Route::livewire('/blog', 'blog')->section('blog');
// For LiveWire 2.
Route::get('/blog' , 'BlogController#index');
});
You are calling the auth middleware and the error is stating there is no LoginController presently located in Auth\LoginController
Do you have any auth scaffolding setup?
Didn't realize this was such an old thread.
With Laravel 8.29 and LiveWire 2.4.0
UnexpectedValueException
Invalid route action: [App\Http\Controllers\App\Http\Livewire\Blog].
I think that is better tha you need create a new Controller in App\Http\Controllers and link the route with this Controller. In the view use #liveware to your LiveWire Controller.
Route::group(['middleware' => 'auth'], function () {
// Only with LiveWire v1
//Route::livewire('/blog', 'blog')->section('blog');
// For LiveWire 2.
Route::get('/blog' , 'BlogController#index');
});
App\Http\Controllers\BlogController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class BlogController extends Controller
{
public function index(){
return view('blog.index');
}
}
resources/views/blog/index.blade.php
#livewire('blog')
Note:
With the fix (https://laravel-livewire.com/docs/2.x/upgrading)
protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace) // Remove me
->group(base_path('routes/web.php'));
}
you will have problems with routes in Middlewares
Illuminate\Contracts\Container\BindingResolutionException Target class
[Auth\LoginController] does not exist.

Laravel: Not picking up __invoke method?

Trying to use invokable controllers, but it seems to fail to find the __invoke method?
Invalid route action: [App\Http\Controllers\App\Http\Controllers\MainController].
It seems to be returning true on:
if (! method_exists($action, '__invoke')) {
throw new UnexpectedValueException("Invalid route action: [{$action}].");
}
Routes:
<?php
Route::get('/', \App\Http\Controllers\MainController::class);
MainController:
<?php
namespace App\Http\Controllers;
class MainController extends Controller
{
public function __invoke()
{
dd('main');
}
}
Laravel by default assumes that your controllers will be located at App\Http\Controllers\. So when you're adding the full path to your controller, Laravel will check it there, at App\Http\Controllers\App\Http\Controllers\MainController.
To solve it simply remove the namespace when you're registering the route, and register it like this:
Route::get('/', MainController::class);
Alternatively, you can stop this behavior by removing ->namespace($this->namespace) from mapWebRoutes() method on RouteServiceProvider class, which is located at App\Providers folder. Then you can register your routes like this:
Route::get('/', \App\Http\Controllers\MainController::class);
Alternatively, you can use:
use App\Http\Controllers\MainController;
Route::get('/', [MainController::class, '__invoke']);
In this case, the namespace provided in RouteServiceProvider won't be taken into account.
The advantage of this is that now your IDE will be able to reference the class usage and you can navigate by clicking on it.
The best answer that works for everyone is laravel documentation.
just use this at the top of your route(web.php) if (websiteController is the name of your controller)
use App\Http\Controllers\WebsiteController;
and define your route like this for your index page
Route::get('/', [WebsiteController::class, 'index']);
take note of the
[ ]
You have to create the crontoller with argument "--invokable"
php artisan make:controller YourController --invokable
Always Declare/Use in Top
use App\Http\Controllers\backend\DashboardController;
Then Use this way
Route::get('/dashboard', [DashboardController::class, 'dashboard'])->name('dashboard');
If have Auth and Use Group
Route::middleware([
'auth:sanctum',
config('jetstream.auth_session'),
'verified'
])->group(function () {
Route::get('/dashboard', [DashboardController::class, 'dashboard'])->name('dashboard');
})
Change your route to:
Route::get('/', "MainController");
In my case I forget to set #action, so change your code from:
Route::get('admin/orders', 'Admin\OrderController')->name('admin.orders');
to:
Route::get('admin/orders', 'Admin\OrderController#index')->name('admin.orders');
you have mentioned get link, but you have not declared which method it should call.
Route::get('/', \App\Http\Controllers\MainController::class);// if you are importing lass like this you have to use resource instead of get.
you can solve this issue by two ways,
first way,
Route::get('/', '\App\Http\Controllers\MainController#index'); // you have to mention your method which you have mentioned in controller
another way is,
Route::resource('/', \App\Http\Controllers\MainController::class);
In, 2nd method laravel will automatically find which request and where should redirect.2nd option is prefered if you are using multiple method for the same route.
Route::resource('/', \App\Http\Controllers\MainController::class);
Use method 'resource'

Class App\Http\Controllers\WelcomeController does not exist

I'm new in Laravel and I can't understand why the controller doesn't work. Can you help me? Thanks.
This is the routes.php file:
routes.php
This is the WelcomeController controller:
WelcomeController.php
and this is the exception trowed:
ReflectionException in Container.php line 737:
Class App\Http\Controllers\WelcomeController does not exist
If you are using the laravel 8 then you can use the below-mentioned code in your web.php route file
use App\Http\Controllers\WelcomeController;
Route::get('/', [WelcomeController::class, 'index'])->name('welcome');
For more information use the laravel 8 documentation https://laravel.com/docs/8.x/routing
You need a WelcomeController.php file in directory Controllers, and you have it in Controllers/Auth
I'd suggest to:
$>php artisan make:controller WelcomeController
if you forget to choose your method:
Route::get('/', 'WelcomeController')->name('welcome');
change it to:
Route::get('/', [WelcomeController::class, 'index'])->name('welcome');
or
Route::get('/', 'WelcomeController#YOUR_METHOD_NAME')->name('welcome');

Categories