Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

durairaj's avatar

php artisan command not working in laravel 8

laravel 8 project working with database, when i change new database and it doest not working, even php artisan command not working

PS C:\xampp\htdocs\laraauth> php artisan

In Connection.php line 712:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'pheonix_crm.company_settings' doesn't exist (SQL: select * from company_settings where id = 1 limit 1)

what have i done. change db name in .env file only.

Please help me. how to solve this error and do php artisan migrate:refresh

0 likes
5 replies
chahal's avatar

Check connection using

php artisan tinker

then

DB::connection()->getPdo();

What error are you getting while running

php artisan 
durairaj's avatar

@dev-chahal

while running php artisan i got response

In Connection.php line 712:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'pheonix_crm.company_settings' doesn't exist (SQL: select * from company_settings where id = 1 limit 1)

Snapey's avatar

The problem is caused by having a database query in a service provider.

Artisan boots the framework in order to run migrations, yet your database table does not yet exist.

You need to find that code and either temporarily comment it out, or wrap it in a conditional that checks for the existence of the table, or uses a try-catch block.

Check your Service Providers first (or just review the stack trace)

Your issue IS NOT with the database connection.

durairaj's avatar

@Snapey Can u please tell me more details.

AppServiceProvider.php

 class AppServiceProvider extends ServiceProvider
 {

 public function register()
{
    
}

public function boot(Request $request)
{
    Paginator::defaultView('vendor.pagination.bootstrap-4');

    Paginator::defaultSimpleView('vendor.pagination.bootstrap-4');
}
}

AuthService Provider.php

class AuthServiceProvider extends ServiceProvider
{
protected $policies = [
    // 'App\Models\Model' => 'App\Policies\ModelPolicy',
];

public function boot()
{
    $this->registerPolicies();
    
}
}

how can i check this.

durairaj's avatar
durairaj
OP
Best Answer
Level 1

problem was solved. i've used view share on all pages through controller.php, when i comment that line it will working.

class Controller extends BaseController
	{
		use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
		public function __construct()
		{
    		//its just a dummy data object.
    		$company_info = DB::table('company_settings')->where('id', 1)->first();
    		$company_subscriptions = DB::table('company_subscriptions')->where('company_id', 1)->first();
    		$meta_data = DB::table('landing_pages')
                    ->select('landing_page_meta_details.*')
                    ->join('landing_page_meta_details', 'landing_page_meta_details.page_id', '=', 'landing_pages.id')
                    ->where('is_default_landing_page', 1)->get();
    View::share('cm_favicon', $company_info->site_favicon ?? '');
    View::share('cm_logo', $company_info->site_logo ?? '');
    View::share('copyrights', $company_info->copyrights ?? '');
    View::share('site_name', $company_info->site_name ?? '');
    View::share('meta_data', $meta_data ?? '');
    View::share('expiry_date', $company_subscriptions->endAt ?? '');
    
}
}

Thank you for replying all.

Please or to participate in this conversation.