Home > Net >  Laravel, infinite loading when I try to display MySQL tables
Laravel, infinite loading when I try to display MySQL tables

Time:10-10

I wanna show all tables of my MySQL database in a Laravel view.
But when I open the website, loads the page endlessly.
How I can fix?

Routes:

<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\DB;

Route::get('/', function () {
    return view('welcome');
});

Route::get('/listen', function () {
    $groups = DB::select('SHOW TABLES');
    return view('listen', ['groups' => $groups]);
});

Page that need to show Tables:

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link href="{{ asset('css/app.css') }}" rel="stylesheet">

        <title>ListenOnce - Homepage</title>

        <!-- Fonts -->
        <link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap" rel="stylesheet">

    </head>
    <body class="bg-dark">
        <div id="app">
            <h1 class="display-1 text-center" style="color: #8800e7; margin-top: 50px">Browse groups</h1>
            @foreach($groups as $group) 
                <div>
                    {{ $group->group_name }}
                </div>
            @endforeach
        </div>
        <script src="{{ mix('/js/app.js') }}"></script>
    </body>
</html>

Database config:

<?php

use Illuminate\Support\Str;

return [

    'default' => 'mysql',

    'connections' => [

        'mysql' => [
            'read' => [
                'host' => [
                    '127.0.0.1'
                ],
            ],
            'write' => [
                'host' => [
                    '127.0.0.1'
                ],
            ],
            'sticky' => true,
            'driver' => 'mysql',
            'database' => 'listenonce',
            'username' => 'root',
            'password' => '',
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'port' => '8080'
        ],

    ],
];

XAMPP panel screenshot

I tried to wait, and give me "Maximum execution time of 60 seconds exceeded" error.
I'm not using the default .env file.
How I can fix?
I'm new to Laravel and MySQL.
Thanks in advance!

CodePudding user response:

Solution

For first, I've changed the MySQL port from 3306 to 8020.
Then I changed the config from this:

<?php

use Illuminate\Support\Str;

return [

    'default' => 'mysql',

    'connections' => [

        'mysql' => [
            'read' => [
                'host' => [
                    '127.0.0.1'
                ],
            ],
            'write' => [
                'host' => [
                    '127.0.0.1'
                ],
            ],
            'sticky' => true,
            'driver' => 'mysql',
            'database' => 'listenonce',
            'username' => 'root',
            'password' => '',
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'port' => '8080'
        ],

    ],
];

To this:

<?php

return [

    'default' => 'mysql',

    'connections' => [

        'mysql' => [
            'read' => [
                'host' => [
                    'localhost:8020'
                ],
            ],
            'write' => [
                'host' => [
                    'localhost:8020'
                ],
            ],
            'sticky' => true,
            'driver' => 'mysql',
            'database' => 'listenonce',
            'username' => 'root',
            'password' => '',
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'port' => '8020'
        ],

    ],
];

Then I've restarted MySQL, Apache and the application and finally works.

  • Related