I'm developing using Laravel 5.2 and l5-repository 2.1. I created some repositories that worked fine, but after a while, I got back to project and self-updated the composer and created some new views and a new model and corresponding repositories. but get the Class not found an exception. as I move the new Model from Models folder to repositories folder the error disappears. can anyone help?
ReflectionException in Container.php line 734:
Class App\Repositories\Tour does not exist
and this is the stack trace:
in Container.php line 734 at ReflectionClass->__construct('App\Repositories\Tour') in Container.php line 734 at Container->build('App\Repositories\Tour', array()) in Container.php line 629 at Container->make('App\Repositories\Tour', array()) in Application.php line 697 at Application->make('App\Repositories\Tour') in BaseRepository.php line 176 at BaseRepository->makeModel() in BaseRepository.php line 92 at BaseRepository->__construct(object(Application)) at ReflectionClass->newInstanceArgs(array(object(Application))) in Container.php line 779 at Container->build('App\Repositories\TourRepositoryEloquent', array()) in Container.php line 629 at Container->make('App\Repositories\TourRepositoryEloquent', array()) in Application.php line 697 at Application->make('App\Repositories\TourRepositoryEloquent', array()) in Container.php line 230 at Container->Illuminate\Container{closure}(object(Application), array()) in Container.php line 731 at Container->build(object(Closure), array()) in Container.php line 629 at Container->make('App\Repositories\TourRepository', array()) in Application.php line 697 at Application->make('App\Repositories\TourRepository') in Container.php line 849 at Container->resolveClass(object(ReflectionParameter)) in Container.php line 804 at Container->getDependencies(array(object(ReflectionParameter), object(ReflectionParameter), object(ReflectionParameter), object(ReflectionParameter), object(ReflectionParameter), object(ReflectionParameter), object(ReflectionParameter), object(ReflectionParameter)), array()) in Container.php line 775 at Container->build('App\Http\Controllers\HomeController', array()) in Container.php line 629 at Container->make('App\Http\Controllers\HomeController', array()) in Application.php line 697 at Application->make('App\Http\Controllers\HomeController') in ControllerDispatcher.php line 67 at ControllerDispatcher->makeController('App\Http\Controllers\HomeController') in ControllerDispatcher.php line 52 at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\HomeController', 'welcome') in Route.php line 174 at Route->runController(object(Request)) in Route.php line 140 at Route->run(object(Request)) in Router.php line 724 at Router->Illuminate\Routing{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
There are two things which might trigger this problem. First is a bad class cache. Try an artisan cache:clear.
The second is that Laravel's autoloader looks for a class based on its namespace. If you're not updating the namespace when looking for the file, Laravel will probably fail to find it.
In repository implementation class TourRepositoryEloquent the model function returns the Tour::class. I changed it to "App\Models\Tour" and it works fine right now. Am I missing anything like configuration?
Related
I am getting this error while updating Laravel 5.1 to 5.2.
BadMethodCallException in Macroable.php line 74:
Method filter does not exist
any help ?
here is stack trace
BadMethodCallException in Macroable.php line 74: Method filter does not exist.
in Macroable.php line 74
at Router->__call('filter', array('auth', object(Closure))) in Facade.php line 219
at Router->filter('auth', object(Closure)) in Facade.php line 219
at Facade::__callStatic('filter', array('auth', object(Closure))) in RouteServiceProvider.php line 56
at Route::filter('auth', object(Closure)) in RouteServiceProvider.php line 56
at RouteServiceProvider->boot(object(Router))
at call_user_func_array(array(object(RouteServiceProvider), 'boot'), array(object(Router))) in Container.php line 507
at Container->call(array(object(RouteServiceProvider), 'boot')) in Application.php line 757
at Application->bootProvider(object(RouteServiceProvider)) in Application.php line 740
at Application->Illuminate\Foundation\{closure}(object(RouteServiceProvider), '18')
at array_walk(array(object(EventServiceProvider), object(RoutingServiceProvider), object(AuthServiceProvider), object(CookieServiceProvider), object(DatabaseServiceProvider), object(EncryptionServiceProvider), object(FilesystemServiceProvider), object(FoundationServiceProvider), object(PaginationServiceProvider), object(SessionServiceProvider), object(ViewServiceProvider), object(LaravelPushNotificationServiceProvider), object(ImageServiceProvider), object(BarcodeServiceProvider), object(CloudderServiceProvider), object(AppServiceProvider), object(ConfigServiceProvider), object(EventServiceProvider), object(RouteServiceProvider)), object(Closure)) in Application.php line 741
at Application->boot() in BootProviders.php line 17
at BootProviders->bootstrap(object(Application)) in Application.php line 203
at Application->bootstrapWith(array('Illuminate\Foundation\Bootstrap\DetectEnvironment', 'Illuminate\Foundation\Bootstrap\LoadConfiguration', 'Illuminate\Foundation\Bootstrap\ConfigureLogging', 'Illuminate\Foundation\Bootstrap\HandleExceptions', 'Illuminate\Foundation\Bootstrap\RegisterFacades', 'Illuminate\Foundation\Bootstrap\RegisterProviders', 'Illuminate\Foundation\Bootstrap\BootProviders')) in Kernel.php line 232
at Kernel->bootstrap() in Kernel.php line 127
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 53
From the stack trace I got this Route::filter('auth', object(Closure)) in RouteServiceProvider.php line 56? So check your RouteServiceProvider.php file in line number 56. You have a filter call. Update it with the v5.2 code. That should fix your issue.
I'm migrating an API from Laravel 5.6 to Lumen 5.6
My app use a plugin of mine that reference Illuminate\Foundation\Auth\User
but Lumen doesn't seem to have it. Is it normal ?
(1/1) Error
Class 'Illuminate\Foundation\Auth\User' not found
in HasRelationships.php line 656
at Model->newRelatedInstance('Illuminate\\Foundation\\Auth\\User')
in HasRelationships.php line 418
at Model->belongsToMany('Illuminate\\Foundation\\Auth\\User', 'competitor', 'championship_id')
in Championship.php line 87
at Championship->users()
in Builder.php line 546
at Builder->Illuminate\Database\Eloquent\{closure}()
at call_user_func(object(Closure))
in Relation.php line 89
at Relation::noConstraints(object(Closure))
in Builder.php line 550
at Builder->getRelation('users')
in Builder.php line 518
at Builder->eagerLoadRelation(array(object(Championship), object(Championship), object(Championship), object(Championship)), 'users', object(Closure))
in Builder.php line 498
at Builder->eagerLoadRelations(array(object(Championship), object(Championship), object(Championship), object(Championship)))
in Builder.php line 466
at Builder->get(array('*'))
in Relation.php line 154
at Relation->get()
in Relation.php line 143
at Relation->getEager()
in Builder.php line 529
at Builder->eagerLoadRelation(array(object(Tournament)), 'championships', object(Closure))
in Builder.php line 498
at Builder->eagerLoadRelations(array(object(Tournament)))
in Builder.php line 466
at Builder->get(array('*'))
in BuildsQueries.php line 77
at Builder->first()
in CompetitorController.php line 35
at CompetitorController->index('fake-tournoi')
at call_user_func_array(array(object(CompetitorController), 'index'), array('fake-tournoi'))
in BoundMethod.php line 29
at BoundMethod::Illuminate\Container\{closure}()
in BoundMethod.php line 87
at BoundMethod::callBoundMethod(object(Application), array(object(CompetitorController), 'index'), object(Closure))
in BoundMethod.php line 31
at BoundMethod::call(object(Application), array(object(CompetitorController), 'index'), array('slug' => 'fake-tournoi'), null)
in Container.php line 564
at Container->call(array(object(CompetitorController), 'index'), array('slug' => 'fake-tournoi'))
in RoutesRequests.php line 373
at Application->callControllerCallable(array(object(CompetitorController), 'index'), array('slug' => 'fake-tournoi'))
in RoutesRequests.php line 339
at Application->callLumenController(object(CompetitorController), 'index', array(1, array('uses' => 'App\\Http\\Controllers\\CompetitorController#index'), array('slug' => 'fake-tournoi')))
in RoutesRequests.php line 313
at Application->callControllerAction(array(1, array('uses' => 'App\\Http\\Controllers\\CompetitorController#index'), array('slug' => 'fake-tournoi')))
in RoutesRequests.php line 275
at Application->callActionOnArrayBasedRoute(array(1, array('uses' => 'App\\Http\\Controllers\\CompetitorController#index'), array('slug' => 'fake-tournoi')))
in RoutesRequests.php line 260
at Application->handleFoundRoute(array(1, array('uses' => 'App\\Http\\Controllers\\CompetitorController#index'), array('slug' => 'fake-tournoi')))
in RoutesRequests.php line 230
at Application->handleDispatcherResponse(array(1, array('uses' => 'App\\Http\\Controllers\\CompetitorController#index'), array('slug' => 'fake-tournoi')))
in RoutesRequests.php line 164
at Application->Laravel\Lumen\Concerns\{closure}(object(Request))
at call_user_func(object(Closure), object(Request))
in Pipeline.php line 52
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request))
in InjectDebugbar.php line 65
at InjectDebugbar->handle(object(Request), object(Closure))
in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request))
in Pipeline.php line 32
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request))
in CorsMiddleware.php line 18
at CorsMiddleware->handle(object(Request), object(Closure))
in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request))
in Pipeline.php line 32
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request))
in Pipeline.php line 104
at Pipeline->then(object(Closure))
in RoutesRequests.php line 410
at Application->sendThroughPipeline(array('App\\Http\\Middleware\\CorsMiddleware', 'Barryvdh\\Debugbar\\Middleware\\InjectDebugbar'), object(Closure))
in RoutesRequests.php line 166
at Application->dispatch(null)
in RoutesRequests.php line 107
at Application->run()
in index.php line 28
at require('/Users/julien/Documents/Proyectos/kz-api/public/index.php')
in server.php line 147
EDIT:
use Illuminate\Foundation\Auth\User;
...
public function users()
{
return $this->belongsToMany(User::class, 'competitor', 'championship_id')
->withPivot('confirmed')
->withTimestamps();
}
If I change Illuminate\Foundation\Auth\User for App\User, it will work, but as this code belongs to a plugin, it is recommended never to make reference to App\User as you never know the namespace of the project in which it will be running
Yes, it is normal. laravel/lumen-framework doesn't pull in laravel/framework it pulls in the submodules from Illuminate, which do not include what is in Illuminate\Foundation.
I have a problem with my routes in Laravel.
When I use the following route:
Route::resource('user', 'PostsController');
The methods PUT and DELETE work fine with the functions destroy and update in my controller, but when I use the following route:
Route::delete('{$id}', function($id){
return "Remover o usuário ".$id;
});
and
Route::put('{$id}', function($id){
return "Editar o usuário ".$id;
});
I have the following error:
NotFoundHttpException in RouteCollection.php line 161:
in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 780
at Router->findRoute(object(Request)) in Router.php line 610
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 267
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in HandleCors.php line 42
at HandleCors->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 56
at require_once('C:\xampp\htdocs\apiRest\public\index.php') in server.php line 21
Bellow follow the image to more details how I send the request
Request
I'm using the Postsman to send the request.
Please, can anyone help me??
In Laravel route parameters are defined without a $ like {id} instead of {$id}. See the docs for more info.
So in your case:
Route::delete('{id}', function($id){
return "Remover o usuário ".$id;
});
and:
Route::put('{id}', function($id){
return "Editar o usuário ".$id;
});
I've created a custom view in the views/errors directory called 404.blade.php per documented in laravel docs Laravel custom http docs , but when I include a master template it throws a ErrorException. If I remove the #extends('master') from the error view and just use custom html it works find. Is there a way to extend or include master template in my error views?
Here's my stack trace.
ErrorException in 6d81dce21d9f786092d4f08b2291187254557680.php line 41:
Trying to get property of non-object (View C:\xampp\htdocs\auto_responder\resources\views\layouts\site_master.blade.php) (View: C:\xampp\htdocs\auto_responder\resources\views\layouts\site_master.blade.php)
in 6d81dce21d9f786092d4f08b2291187254557680.php line 41
at CompilerEngine->handleViewException(object(ErrorException), '1') in PhpEngine.php line 44
at PhpEngine->evaluatePath('C:\xampp\htdocs\auto_responder\storage\framework\views/a853a92ee6 c1570e0a223b96c01698d12a46f009.php', array('__env' => object(Factory), 'app' => object(Application), 'exception' => object(NotFoundHttpException))) in CompilerEngine.php line 59
at CompilerEngine->get('C:\xampp\htdocs\auto_responder\resources\views/errors/404.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'exception' => object(NotFoundHttpException))) in View.php line 149
at View->getContents() in View.php line 120
at View->renderContents() in View.php line 85
at View->render() in Response.php line 53
at Response->setContent(object(View)) in Response.php line 201
at Response->__construct(object(View), '404', array()) in ResponseFactory.php line 57
at ResponseFactory->make(object(View), '404', array()) in ResponseFactory.php line 71
at ResponseFactory->view('errors.404', array('exception' => object(NotFoundHttpException)), '404', array()) in Handler.php line 156
at Handler->renderHttpException(object(NotFoundHttpException)) in Handler.php line 113
at Handler->render(object(Request), object(NotFoundHttpException)) in Handler.php line 48
at Handler->render(object(Request), object(NotFoundHttpException)) in Pipeline.php line 80
at Pipeline->handleException(object(Request), object(NotFoundHttpException)) in Pipeline.php line 54
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 54
So I guess my question is, is this suppose to be like this, or am I doing something wrong. All my other views work perfectly using the exact same syntax to extend.
I have a simple quiz app I'm writing where there is a series of challenges (Easy, Medium, Hard), each with their own questions.
The questions to be added should be unique.
I have the following code to "store" the data
$v = ChallengeQuests::validate(Input::all());
if ( $v->passes() ) {
print 'validate passed';
$record = ChallengeQuests::create(array(
'challenge_id'=> (int) Input::get('challenge_id'),
'question_id'=> (int) Input::get('question_id')
));
$record->save();
return redirect()->to($url['redirects_to']);
} else {
print 'error';
print_r($v->getMessages());
return Redirect::to('/')->withErrors($v->getMessages());
}
In my model I have a validation method
// model
class ChallengeQuests extends Model
{
//
protected $table = 'challengequests';
protected $fillable=[
'challenge_id',
'question_id'
];
public static function validate($input) {
$rules = array(
'challenge_id' => 'Required|Integer',
'question_id' => 'Required|Integer|Unique:questions,id'
);
return Validator::make($input, $rules);
}
}
But when I run my code, Laravel complains
BadMethodCallException in Validator.php line 3016:
Method [getMessages] does not exist.
I'm wanting it so that the question_id is unique.
What am I doing wrong?
Edit:
I am using:
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Input;
Stack trace:
BadMethodCallException in Validator.php line 3016:
Method [getMessages] does not exist.
in Validator.php line 3016
at Validator->__call('getMessages', array()) in ChallengeQuestionsController.php line 78
at ChallengeQuestionsController->store(object(Request))
at call_user_func_array(array(object(ChallengeQuestionsController), 'store'), array(object(Request))) in Controller.php line 80
at Controller->callAction('store', array(object(Request))) in ControllerDispatcher.php line 146
at ControllerDispatcher->call(object(ChallengeQuestionsController), object(Route), 'store') in ControllerDispatcher.php line 94
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
at ControllerDispatcher->callWithinStack(object(ChallengeQuestionsController), object(Route), object(Request), 'store') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\ChallengeQuestionsController', 'store') in Route.php line 174
at Route->runController(object(Request)) in Route.php line 140
at Route->run(object(Request)) in Router.php line 724
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Router.php line 726
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 53
at require_once('/Applications/XAMPP/xamppfiles/htdocs/laravel/scquiz/public/index.php') in server.php line 21
The correct method used to get the validation messages is not getMessages() it's messages(), so your code should look like this:
return Redirect::to('/')->withErrors($v->messages());
Also if you're using Laravel 5, you might want to look into using Form Request Validation which does the same thing you're trying to achieve but in a nicer way, and handles the validation on a different layer, taking care of passing the errors and page redirection for you.
By using a Form Request in your case, the controller method would be reduced to this:
public function store(ChallangeQuestsFormRequest $request)
{
ChallengeQuests::create($request->only('challenge_id', 'question_id'));
return redirect()->to($url['redirects_to']);
}
Since the rules and validation as well as redirection in case of an error, would be handled by the ChallangeQuestsFormRequest class. Also, using create to create a model entry will automatically save the entry, so there's no need to use save on the result of create.