I try extend Validator class. I need add a few methods, that I'd like extend all class not use Validator::extend();
I added in vendor direcotry structure:
-comjaroapp
-src
-Comjaroapp
-Validation
-Validator.php
-ValidatorServiceProvider.php
In my config/app.php in providers array, I added:
'Comjaroapp\Validation\ValidatorServiceProvider'
Code to test is simple:
Validator:
namespace Comjaroapp\Validation;
class CustomValidator extends \Illuminate\Validation\Validator{
public function validatePesel($attribute,$value,$options=null){
return true;
}
}
ValidatorServiceProvider:
namespace Comjarospp\Validation;
use Illuminate\Support\ServiceProvider;
class ValidatorServiceProvider extends ServiceProvider{
public function register(){}
public function boot(){
$this->app->validator->resolver(function($transator,$data,$rules,$messages){
return new CustomValidator($transator,$data,$rules,$messages);
});
}
}
After run composer update I see error:
> Error Output: PHP Fatal error: Class
> 'Comjaroapp\Validation\ValidatorServiceProvider' not found in
> /vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php
> on line 158
When I looked on other extension all work with same structure.
If someone have idea, what is wrong or when should I search, please help.
Thanks in advance.
You have different names for your namespaces:
Comjarospp\Validation
and
Comjaroapp\Validation
EDIT:
After fixing the namespace name, have you executed
composer dumpautoload
?
Related
I am new to repository in laravel and trying to work on it , But when i run the application it throws the error
Class 'App\Repositories\User\UserRepoServiceProvider' not found
My interface and repository files are located in App\Repositories\User where Service Provider is also located
Here is my service provider
namespace App\Repositories\User
use Illuminate\Support\ServiceProvider;
class UserRepoServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind('App\Repositories\User\userinterface','App\Repositories \User\userrepository');
}
}
Here is my userrepository.php
namespace App\Repositories\User
use App\Repositories\User\userinterface;
use App\car;
class userrepository implements userinterface
{
public function __construct(car $car){
$this->car = $car;
}
public function get($id)
{
return $this->car->findCar($id);
}
public function delete($id)
{
return $this->car->deleteCar($id);
}
}
Here is my interface userinterface.php
namespace App\Repositories\User;
interface userinterface{
public function get($id);
public function delete($id);
}
I have also registered it in config/app.php file
App\Repositories\User\UserRepoServiceProvider::class
I did composer dump-autoload -o but no use. I cannot do composer update , when i do it throws the same error
I usually check in bootstrap/cache/config.php for the package, sometimes after composer remove nameofthepackage, the package is still listed there
You have to register the service provider in config/app.php.
https://laravel.com/docs/5.3/providers#registering-providers
I'm facing this problem Class 'App\Respositories\BackendServiceProvider' not found
It was due to spelling mistake in config/app.php file. I changed Respositories to Repositories and open this BackendServiceProvider and changed namespace also. so problem has been solved.
Respositories to Repositories
namespace App\Respositories to namespace App\Repositories;
Working for me. You can try it!
Remove "laravel/ui" reference and its provider from packges.php file.
I using Laravel, I have a Model class under App/Models
<?php
namespace App\Models;
class TodoList extends \Eloquent{
public function listItems(){
return $this->hasMany('TodoItem');
}
}
In my Controller I have included the namespace as follows:
namespace App\Http\Controllers;
...
use App\Models\TodoItem;
use App\Models\TodoList;
class TodoListController extends Controller
My method looks like this:
public function show($id)
{
$list=TodoList::findOrFail($id);
return \View::make('todos.show')->with('list', $todo_list);
}
but when I call to a request i get the error:
FatalErrorException in TodoListController.php line 75: Class
'App\Models\TodoList' not found
Trying running composer dump-autoload. Basically your classes become cached so you need to tell Laravel to look for newly added classes.
I'm not sure, just try this :
namespace App\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class TodoList extends Eloquent{
public function listItems(){
return $this->hasMany('TodoItem');
}
}
Here is the code from the docs, but for your example. Note the use Model:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class TodoList extends Model {
//insert public function listItems() here
}
Hope this is helpful!
Make sure the file is in the correct folder and has the same name caption as the Class you want to import.
If the caption of the file "TodoList" is not TodoList.php but Todolist.php for example, Laravel wont find it.
Depending on your setup running "composer dump" might help to refresh autoload files.
The Laravel documentation clearly describes how to change your routes if you nest your controllers in folders. It seems REALLY simple, and yet I'm still getting an error. Here's the error:
"Class App\Http\Controllers\Input\InputController does not exist"
^That path looks 100% correct to me. What gives?
File Structure:
-Controllers
--Auth
--Input
---InputController.php
Routes:
Route::get('input', 'Input\InputController#getInput');
InputController:
<?php namespace App\Http\Controllers;
use Illuminate\Http\Response;
class InputController extends Controller
{
public function getInput()
{
return response()->view('1_input.input_form');
}
}
Thanks for any help!
Change Controller namespace from
namespace App\Http\Controllers
to
namespace App\Http\Controllers\Input
namespace needs to be changed to the directory your controller is in 'App\Http\Input'
You need to pull in Controller with use App\Http\Controllers\Contoller so that you can extend it.
<?php
namespace App\Http\Controllers\Input;
use App\Http\Controllers\Controller; // need Controller to extend
use Illuminate\Http\Response;
class InputController extends Controller
{
public function getInput()
{
return response()->view('1_input.input_form');
}
}
you should try running a couple commands in your base dir from your terminal (shell/prompt):
composer dump-autoload
or if you don't have composer set as executable:
php composer dump-autoload
and then:
php artisan clear-compiled
This way your laravel would prepare everything again "from scratch" and should be able to find the missing controller class.
Basically laravel generates some additional files to boot up faster. If you define a new class it doesn't get included into that "compiled" file. This way your class should be "introduced" to the framework.
I have this class in a workbench package:
class SomeClass{
//Constructor
function __construct(){
$isAuth = Auth::check();
}
But it gives me following error:
Class 'vendor\pachage\Auth' not found
Is this a namespace issue? I am using the following namespace:
namespace vendor\pachage;
You need Fully qualified name, add a backslash:
\Auth::check();
It all described as Namepace resolution.
This is my first question, besides I'm not english-native speaker, so sorry in advance for newbie mistakes...
I'm starting with Symfony2, and I've been facing an autoload problem for a couple of days, i'm getting crazy..
I'm just trying to use a PHP class inside my DefaultController of my AppBundle. I've read the way of doing this is by creating a service in my config.yml and giving a namespace to that class that matches.
Symfony tells me that it does found the file but the class is not in it, the exact error is:
The autoloader expected class "Priceget\CollectorBundle\Crawler\Amazon" to be defined in file "/srv/www/lol.com/public_html/priceget/symfony/src/Priceget/CollectorBundle/Crawler/Amazon.php". The file was found but the class was not in it, the class name or namespace probably has a typo.
And my class is just this:
<?php
namespace Priceget\CollectorBundle\Crawler\Amazon;
use Symfony\Component\HttpFoundation\Response;
class Amazon
{
public function getAll()
{
return new Response('l0l');
}
}
In my DefaultController I'm calling it like that:
<?php
namespace Priceget\CollectorBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Guzzle\Http\Client;
use Symfony\Component\DomCrawler\Crawler;
use Priceget\CollectorBundle\Crawler\Amazon;
class DefaultController extends Controller
{
public function indexAction()
{
$amazon = $this->get('amazon.crawler');
}
}
And my config.yml piece:
services:
amazon.crawler:
class: Priceget\CollectorBundle\Crawler\Amazon
I've already tried to:
Empty cache
Restart apache
Extend the class to Controller? :-Z
Thank you so much in advance.
Your namespace is wrong, rename it:
from: namespace Priceget\CollectorBundle\Crawler\Amazon;
to: namespace Priceget\CollectorBundle\Crawler;
This error also occurs if you do not put <?php in the beginning of the file.
In addition to what's said by Igor, you obviously have to change the FQN class name in the service declaration (YML) if you want it to work.
This can be a bit misleading, it also happens if you don't extend your class correctly. In my instance I tried to extend a repository with an incorrect FQN:
class FilesRepository extends Doctrine\ORM\EntityRepository
should have been:
class FilesRepository extends \Doctrine\ORM\EntityRepository
Notice the missing backslash (\).