I'm using Laravel 5.1.*. Installed defender and created my role 'admin'...But when will using the middleware 'needsRole' (in routes.php) or 'Defender::hasRole('admin')' (in controller) not working.
Message error
BadMethodCallException in Builder.php line 2093:
Call to undefined method Illuminate\Database\Query\Builder::hasRole()
make sure of two things use the trait in your model Artesaos\Defender\Traits\HasDefender and register the service provider then do a composer dump-autoload
Related
Hi I got this errors in Lumen
FatalErrorException in RedirectResponse.php line 75:
Call to a member function flashInput() on null
in RedirectResponse.php line 75
at Application->handleShutdown() in RegistersExceptionHandlers.php line 55
at Application->Laravel\Lumen\Concerns{closure}()
Here the code which throws the error:
return redirect('formular')
->withErrors($validator)
->withInput();
The error comes from withInput()
The error is happening because Lumen 5.2 does not support sessions. The withErrors() and withInput() methods attempt to set values on the session attribute on the redirector, but the session attribute is null.
From the Lumen 5.2 documentation on validation:
Lumen does not support sessions out of the box, so the $errors view variable that is available in every view in Laravel is not available in Lumen. The $this->validate helper will always return JSON responses with the relevant error messages when validation fails. If you are not building a stateless API that solely sends JSON responses, you should use the full Laravel framework.
Basically, if you're trying to use sessions, you're trying to use Lumen 5.2 in a way it was not intended. You should either be using Lumen 5.1, or using the full Laravel framework. You can read the release notes here on the philosophy change for Lumen 5.2.
Whenever I try to run composer update I now receive an error with a root cause of the following
Call to undefined method Illuminate\Bus\Dispatcher::mapUsing()
I can confirm Laravel 5.2 is properly installed, as are all other dependencies. This only happens when php artisan clear-compiled is run.
I've also updated my base controller based on a suggestion from a few hours ago in the Laracasts forum
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
abstract class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
But I still receive the error
UPDATE: This happens whenever the application is bootstrapped at all. My app won't even run now.
UPDATE 2, full stack trace:
PHP Fatal error: Call to undefined method Illuminate\Bus\Dispatcher::mapUsing() in /Users/Zara/Web/cafe/app/Providers/BusServiceProvider.php on line 16
PHP Stack trace:
PHP 1. {main}() /Users/Zara/Web/cafe/artisan:0
PHP 2. Illuminate\Foundation\Console\Kernel->handle() /Users/Zara/Web/cafe/artisan:36
PHP 3. Illuminate\Foundation\Console\Kernel->bootstrap() /Users/Zara/Web/cafe/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:105
PHP 4. Illuminate\Foundation\Application->bootstrapWith() /Users/Zara/Web/cafe/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:208
PHP 5. Illuminate\Foundation\Bootstrap\BootProviders->bootstrap() /Users/Zara/Web/cafe/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:203
PHP 6. Illuminate\Foundation\Application->boot() /Users/Zara/Web/cafe/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php:17
PHP 7. array_walk() /Users/Zara/Web/cafe/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:718
PHP 8. Illuminate\Foundation\Application->Illuminate\Foundation\{closure}() /Users/Zara/Web/cafe/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:718
PHP 9. Illuminate\Foundation\Application->bootProvider() /Users/Zara/Web/cafe/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:717
PHP 10. Illuminate\Container\Container->call() /Users/Zara/Web/cafe/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:734
PHP 11. call_user_func_array:{/Users/Zara/Web/cafe/vendor/laravel/framework/src/Illuminate/Container/Container.php:507}() /Users/Zara/Web/cafe/vendor/laravel/framework/src/Illuminate/Container/Container.php:507
PHP 12. Cafe\Providers\BusServiceProvider->boot() /Users/Zara/Web/cafe/vendor/laravel/framework/src/Illuminate/Container/Container.php:507
[Symfony\Component\Debug\Exception\FatalErrorException]
Call to undefined method Illuminate\Bus\Dispatcher::mapUsing()
From the Laravel 5.2 Upgrade Guide
Separate Commands & Handlers
The Laravel 5.2 command bus now only supports self-handling commands and no longer supports separate commands and handlers.
If you would like to continue using separate commands and handlers, you may install a Laravel Collective package which provides backwards-compatible support for this: https://github.com/LaravelCollective/bus
There is no longer support for non self handling commands which is what the mapper would be for; mapping commands to handlers.
Check Service Providers
Check any service providers you have registered to make sure they aren't calling that method on dispatcher. If still having that issue, you can try checking any package service providers to make sure they aren't calling that method.
I am migrating a Laravel 4.2 application to Laravel 5.1.
During bootstrap, when loading the mail configuration file (config/mail.php), I want to read my SMTP configuration from DB and cache it.
In order to do that I use an Eloquent model class, in which I use the Cache facade's remember() function to get the data I need.
It used to work in 4.2, but after switching to 5.1, I get the following error message:
Call to a member function remember() on a non-object
This happens after I put the following line at the top of the class:
use Illuminate\Support\Facades\Cache;
Without that line I got a Class 'Cache' not found error message.
Any idea what am I missing? Is this even possible in 5.1?
Thanks a lot!
I am using Laravel 5. I have created one service folder inside app. I am trying to access the class of service folder from a controller method. I have tried
method injection
as well as
contructor injection
. Both way I am getting the error :
ReflectionException in Container.php line 833:
Class app\Services\NameOTheClass does not exist
If I use the symfony console command generate:doctrine:crud with --write parameter I get an auto-generated controller working only in the indexAction route, but not in the others (newAction, deleteAction, updateAction). I think the problem is in the form creation.
The resulting error is the following one:
Compile Error: Can't inherit abstract function
Symfony\Component\Validator\ValidatorInterface::validate() (previously
declared abstract in
Symfony\Component\Validator\Validator\ValidatorInterface)
Server Error - FatalErrorException500 Internal in vendor/symfony/symfony/src/Symfony/Component/Validator/Validator/RecursiveValidator.php at line 31
I don't know, how to solve this problem.
This error is the error message you get when running the new validator component in PHP 5.3.8 or older. You need to use at least PHP 5.3.9 to use recent versions of Symfony
The only way to solve this problem is to change ValidatorInterface or to run almost PHP 5.6