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

Armani's avatar
Level 17

Check table existence before getting query

I have some queries in AppServiceProvider and I want to check if table exists then run them.

I tried Schema like this:

if(Schema::hasTable('mytable'))
{	
	run query
}

but it didn't work.

0 likes
1 reply
Sinnbeck's avatar

That should work? How isn't it working?

if (Schema::hasTable('mytable')) {
  //do stuff 
} 
 

Please or to participate in this conversation.