Siege21x Siege21x - 4 months ago 58
MySQL Question

Laravel routing & database MySQL different output

I am studying Laravel Framework for few hours and i am trying to do what's being done in the tutorial i am watching. I am executing a query through routes.php and it's giving me a different output.

My database has only 1 table and it is named 'customer' and i have a model named 'customer' and a controller named 'CustomerController'

My routes.php code is this

Route::get('customer', function() {
$customer = FirstLaravelApplication\Customer::find(1);
echo '<pre>';

But the localhost is giving me an error and it says i don't have any 'customers' table, it automatically added a letter 's' in the end of the table instead of 'customer' only. i really don't have any 'customers' table i don't know why it is passing the wrong name of the table but my code only says 'customer'.

i would appreciate any help! Thanks all!


Laravel/Eloquent ORM uses this convention, as do many ORMs. They pluralize table names.

Open up the Customer.php model and add in:

class Customer extends Model {

    // Add this
    protected $table = 'customer';

However, it's usually easier to stick with the framework's conventions.