I am new to laravel and use the laravel 9.37v version. I have the following error message.
I created a blade template. I could view that blade template using view but after I tried to view that template using the controller I got this error message.
Target class [PagerConntroller] does not exist
Please check the spelling, if it is correct try to import the controller class in the Route. Im assuming the controller name is PagerConntroller and the function that you need to call is index so your web.php or api.php should be like :
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PagerConntroller;
Route::get('view',[PagerConntroller::class, 'index']);
Or else you can use the controllers without importing by simply uncommenting the namespace variable inside app/Providers/RouteServiceProvider.php line:29 the variable will look like protected $namespace = 'App\\Http\\Controllers'; then your route file should be like
<?php
use Illuminate\Support\Facades\Route;
Route::get('view','PagerConntroller#index');
If you tried both the ways and still the error persists kindly check your class name and the namespace as well
Related
I try to set up kakao login to my Shopify store, but when I run the test I encountered this message error, what should I do? Thank you
The Cache facade doesn't live in the App\Http\Controllers namespace. If you do not include a use statement at the top of your PHP files for your classes, it is assumed the class does live in the same namespace.
The Laravel Cache facade lives in the Illuminate\Support\Facades namespace so at the top of your KakaoController with your other use statements, add the following:
use Illuminate\Support\Facades\Cache;
You must need to add "use Illuminate\Support\Facades\Cache;" on top of controller, middleware, command, event or blade files.
for example
<?php namespace App\Http\Controllers;
use Illuminate\Support\Facades\Cache;
class KaKaoController extends Controller {
...
or "use \Cache;"
I created a UserController inside
app/Http/Controllers/API/UserController.php
Inside the UserController.php I have this
namespace App\Http\Controllers\API;
Inside the api.php I have this
Route::apiResources(['user' => 'API\UserController']);
I get this error below when I try to display the route list.
Error: Target class [App\Http\Controllers\UserController] does not
exist.
How do we tell Laravel that the UserController is inside app/Http/Controllers/API?
You need to defined the namespace, so laravel can find the controller:
<?php
namespace App\Http\Controllers\API;
...
class UserController extends Controller {
You have already defined the api.php with namespace API:
Route::apiResources(['user' => 'API\UserController']);
Try to clear the routes cache:
php artisan route:clear
php artisan optimize
Have you checked that the path you specify is correct ?
and you could also check the namespace in the UserController, correspond to:
namespace App\Http\Controllers\API ?
Or also you can simply add the controllers in the wep / api routes :
Route::get('prefix', 'DirOfYourController\YourController#SomeFunction);
Or as stated on the documentation you could take a look here:
https://laravel.com/docs/master/routing#route-group-namespaces
Well it's definitely because one of your web.php or api.php file
make sure that namespace of the file is correct in there for instance
Route::get('foo', 'API\UserController');
You need to follow only 2 steps to achieve the same:
Step1:
Define the correct name space in your UserController as below
namespace App\Http\Controllers\API;
Step2: Define route with directory name in your web.php for eg.
Route::get('dashboard', 'API\UserController#dashboard');
I am having problems with autocompletion in PhpStorm using Laravel. I have set up the IDE accordingly from this guide:
https://confluence.jetbrains.com/display/PhpStorm/Laravel+Development+using+PhpStorm
I cannot autocomplete basic functions like Input::only or Input::has. The closest answer I can find is in this thread:
Laravel Intellisense / autocomplete with PhpStorm
However, Input is already added as alias in config/app.php - still not working.
Anyone experienced same problem and/or know a solution to this?
EDIT:
Sorry for not providing code example - it's only been some Laravel trial and error, but here goes:
I have the route:
Route::post('/login', 'LoginController#authenticate');
In the action of the controller I have tried the following:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
class LoginController extends Controller
{
public function authenticate(Request $request) {
Input::get(); // <-- autocompletes
Input::has(); // <-- NO autocomplete
$request->only(); // <-- autocompletes
$request->validate(); // <-- NO autocomplete
}
}
use laravel ide-helper package
it can provide accurate autocompletion. Generation is done based on the files in your project.
phpstrom support auto-complete best thing is that
I'm new to Laravel. I just installed Laravel 5 and have been going through some video tutorials in order to learn how it works.
I want to use the User class as it seems like it is very useful. In my web.php (routes) file, I have:
use app\Models\User;
Route::get('/users', function (){
$users = User::all(); //select * from users
return $users;
});
I get the following error upon loading that route in my browser:
I have a User.php file placed in my app/Models/ directory, and also changed in my auth.php file for it to reference this.
There are countless questions like this online and I try the fixes but I can't seem to get it to work. Any ideas?
Thanks!
Remove Models from use statement. It's not directory... Model is in namespace App so use:
use App\User;
Namespace and Directory is completely different things...
Or if you want to use in directory app/Models go to User.php model file and change namespace from App to App\Models
I'm facing a problem in uploading images to server in laravel 5, the problem is some images uploaded normally, and other images breaks the server, and I got this message
The specified URL cannot be found.
I'm using this route in routes.php
Route::any('/{lang}/REGISTER','createAccountController#index');
My class is :
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Foundation\Application;
use App\Http\Requests;
use Request;
use Route;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Lang;
use App\ImageCircleCrop;
class createAccountController extends Controller
{
public function index($lang,Request $request){
// process form data here
}
}
I don't get any error messages in server logs, in fact, the application does not reach the controller code at all. Any help?
New Update: I noticed that the problem occurs just for png images, submitting form with file of type png make a crash on the application. The route does not work after that, and I got the message: "The specified URL cannot be found". Is it something related to the server configuration, or with laravel configration?