Laravel artisan route:list shows non-object Exception - php

I am new to laravel. Recently I cloned sample project from github. When I try to execute php artisan route:list shows
PHP Fatal error: Call to a member function getMemberType() on a non-object in /...app/Http/Controllers/Admin/BaseAdminController.php on line 91
[Symfony\Component\Debug\Exception\FatalErrorException]
Call to a member function getMemberType() on a non-object
BaseAdminController.php
public function __construct(EmployeeDetails $employeeDetails)
{
$this->middleware('auth');
if(Auth::user()->getMemberType() != 'employee') //Line 91
{
Auth::logout();
return Redirect::to('secure/login');
}

When you fire artisan task, user object is not set, so \Auth::user() returns null and you see this error.
That's why you have to check if your app is running in console. You can do it via \App::runningInConsole() method.

Related

$request->route() returns null in laravel

I have this code:
class TotersProviderLoginController extends Controller
{
private $oauthService;
public function __construct(Request $request)
{
$provider = $request->route()->parameter('provider'); // error here
if($provider == 'google')
$this->oauthService = new GoogleOauthService();
else
throw new \Exception('Provider '.($provider ?? '').' not supported!');
}
I have the following routes defined:
Route::get('login/toters/{provider}', 'Accounts\TotersProviderLoginController#redirectToProvider');
Route::get('login/toters/{provider}/redirect', 'Accounts\TotersProviderLoginController#handleProviderCallback');
Route::get('login/toters/{provider}/csrf', 'Accounts\TotersProviderLoginController#getCsrf');
Route::post('login/toters/{provider}/oauth', 'Accounts\TotersProviderLoginController#requestToken');
for some reason when I run
php artisan route:list --verbose
I get this error
In TotersProviderLoginController.php line 38:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Call to a member function parameter() on null
so it's clear that $request->route() is returning null. Why is that?
note: I'm using Laravel 5.8
I have debug myself as you mentioned in the question and i found the way where you get the error.
When you run php artisan route:list --verbose command it will debug all routes and also call controller methods of every routes.
In your case what happens when you run command with verbose, route do not have provider default value and that's why it always gives null value.
While you call routes via postman or web it will definitely work, because at that time you have always some value for provider.
Thanks:)

error Commands out of sync; you can't run this command now

Error Message:
**Error Number: 2014
Commands out of sync; you can't run this command now
call allBarang('','')
Filename: C:/xampp/htdocs/jualbarang/application/models/dbAll.php
Line Number: 18**
I don't know why cannot call 2 models in same function, I set function in index() because first page must have some models
/system/database/drivers/mysqli/mysqli_result.php
CodeIgniter does not currently allow more than one stored procedure to be run during the same request.
The following method was added to the CI_DB_mysqli_result class:
function next_result()
{
if (is_object($this->conn_id))
{
return mysqli_next_result($this->conn_id);
}
}
Source: http://forum.codeigniter.com/thread-758.html

Getting Fatal error on executing a test on Behat+Mink+Selenium

I am executing the test on Behat+Mink+Selenium. Below is the code which is have added in the FeatureContext.php:
/**
* #Given /^\|I am on "([^"]*)"$/
*/
public function iAmOn($arg1)
{
$this->visit($arg1);
}
Below is the error which i am getting:
Feature: Drupal.org search
In order to find modules on Drupal.org
As a Drupal user
I need to be able to use Drupal.org search
#javascript
Scenario: Searching for "behat" # features\test1.feature:7
PHP Fatal error: Call to a member function getSession() on null in C:\Behat Demo1\vendor\behat\mink-extension\src\Behat\MinkExtension\Context\RawMink
Context.php on line 103
Fatal error: Call to a member function getSession() on null in C:\Behat Demo1\vendor\behat\mink-extension\src\Behat\MinkExtension\Context\RawMinkConte
xt.php on line 103
Please help.

WordPress wp_oembed_get error

I'm having issues with a video shortcode in wordpress and decided to create a php script to test the wp_oembed_get function and make sure that everything was working fine, but when I call:
$embed_code = wp_oembed_get('http://vimeo.com/XXXX', array('width'=>400));
I'm getting this:
Fatal error: Call to a member function get() on a non-object in /var/www/html/xxxxx/wp-includes/cache.php on line 113
Any ideas?

Laravel orWhereHas returning php fatal error

This is strange.
On my development machine (vagrant w/ Debian Wheezy, PHP 5.5.7), the following eloquent query works as expected:
Company::whereUserId($user_id)->orWhereHas('users', function($q) use ($user_id) {
$q->where('users.id', '=', $user_id);
});
My 'Company' model defines the relationship:
public function users()
{
return $this->belongsToMany('User', 'company_user', 'company_id', 'user_id');
}
However, on production, same OS and PHP version I am getting a FATAL PHP error:
PHP Fatal error: Call to a member function getQuery() on a non-object in /var/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php on line 247
I am stumped. I have tried just ->has('users), which works so I know the foreign model is being used. But it is so strange that I am getting different results per environment! Any thoughts?

Categories