Level 53
Have you tried DB::connection('foo')->select(...);?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a php file I need stored in my public directory but I need to load eloquent or DB so I can interact with my database. Tried the below but I get a Failed to open file error, can't be found.
$app = require __DIR__ . '../../../bootstrap/app.php';
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Database\Eloquent\Model;
use \App\Models\LeadSource;
$lead_source_id = LeadSource::where('number', '=', '9104541234')->pluck('id');
print_r($lead_source_id);
Is there a way I can access the database from a PHP file in the public folder without doing mysqli and entering the DB credentials again?
Please or to participate in this conversation.