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

bipin_1611's avatar

Database connection [channels] not configured.

Hello there,

i am error on channels table Database connection [channels] not configured.

Please let me know if you need anything

0 likes
12 replies
tykus's avatar

Database connection not configured suggests you are not using channels as a table name, but rather a connection key. Do you have a Model with a $connection property assigned to 'channels'?

tykus's avatar

Can you show that model code?

bipin_1611's avatar

here is

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Channel extends Model
{
    use HasFactory;

    public function getRouteKeyName()
    {
        return 'slug';
    }

    public function threads()
    {
        return $this->hasMany(Thread::class);
    }
}

tykus's avatar

That's not enlightened me any... what about your .env and your config/database.php; have you inadvertently added channels as the default connection / DB_CONNECTION?

bipin_1611's avatar

i am using php artisan serve and For Database connection, i am using XAMPP.

Here is my .env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=forum
DB_USERNAME=root
DB_PASSWORD=
tykus's avatar

Somewhere you must be setting the database connection at runtime. Are you using a Query Builder anywhere like this:

DB::connection('channels')->...
bipin_1611's avatar

i am using Eloquent Relationships for the database query.

Please help me here

bipin_1611's avatar
public function store(Request $request)
    {
//        dd($request->all());

        $this->validate($request, [
            'title' => 'required',
            'body' => 'required',
            'channel_id' => 'required|exists:channels.id',
        ]);

        $thread = Thread::create([
            'title' => request('title'),
            'body' => request('body'),
            'channel_id' => request('channel_id'),
            'user_id' => auth()->id()
        ]);

        return redirect($thread->path());
    }
tykus's avatar
tykus
Best Answer
Level 104
'channel_id' => 'required|exists:channels,id',

Should be channels,id, the . implies connection.

Please or to participate in this conversation.