thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.72k stars 2.67k forks source link

Unable to add BREAD to table #5843

Open admiralmedia opened 4 months ago

admiralmedia commented 4 months ago

Laravel version

9.52.16

PHP version

8.3.3-1+0~20240216.17+debian10~1.gbp87e37b

Voyager version

1.7

Database

MariaDB version 10.3.39

Description

I'm trying to create a simple project but got stuck on the first step as follows.

  1. Installed a brand new Laravel
  2. Installed a brand new Voyager
  3. Created a table named Test with 3 columns: id, Test1, Test2. Table created as project.Test
  4. Add BREAD with default settings and save.
  5. Try to browse newly created BREAD but all I've got is 500 Error as bellow: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'project.tests' doesn't exist (SQL: selectTest.* fromtestsorder bycreated_atdesc) {"userId":1,"exception":"[object] (Illuminate\\Database\\QueryException(code: 42S02): SQLSTATE[42S02]: Base table or view not found: 1146 Table 'project.tests' doesn't exist (SQL: selectTest.* fromtestsorder bycreated_atdesc) at /home/project/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760)

As I undestand the table name is created as singular but the browse BREAD is looking for the plural name of the table!

Steps to reproduce

I'm trying to create a simple project but got stuck on the first step as follows.

  1. Installed a brand new Laravel
  2. Installed a brand new Voyager
  3. Created a table named Test with 3 columns: id, Test1, Test2. Table created as project.Test
  4. Add BREAD with default settings and save.
  5. Try to browse newly created BREAD but all I've got is 500 Error as bellow: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'project.tests' doesn't exist (SQL: selectTest.* fromtestsorder bycreated_atdesc) {"userId":1,"exception":"[object] (Illuminate\\Database\\QueryException(code: 42S02): SQLSTATE[42S02]: Base table or view not found: 1146 Table 'project.tests' doesn't exist (SQL: selectTest.* fromtestsorder bycreated_atdesc) at /home/project/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760)

Expected behavior

Browse the BREAD

Screenshots

bread1

Additional context

No response

Emerica commented 4 months ago

Change the database table to "tests". You want to make your table names plural in most cases.

admiralmedia commented 4 months ago

Change the database table to "tests". You want to make your table names plural in most cases.

I've created(also renamed) several times the table with name Tests(plural form) but all I got was the same error when browsing Bread:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'project.tests' doesn't exist (SQL: selectTests.* fromtestsorder bycreated_atdesc) {"userId":1,"exception":"[object] (Illuminate\\Database\\QueryException(code: 42S02): SQLSTATE[42S02]: Base table or view not found: 1146 Table 'project.tests' doesn't exist (SQL: selectTests.* fromtestsorder bycreated_atdesc) at /home/project/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760)

admiralmedia commented 4 months ago

I've figured out what the issue was as follows:

Jhamende commented 3 months ago

Hello,

Tables needs names in all small letters and plural.

Not Test, not Tests, not test But should be tests

Kind regards John

rawtion commented 3 months ago

manually create model for Test (model name) better to reallocate model directly inside app folder App i.e: Modal Name = 'App\Models\Test**' php artisan make:model Test

add below codes on Test Model

` class Test extends Model { protected $primaryKey='id';

use HasFactory;
public $table= 'Test';
public $timestamps=false;

`