FrozenNode / Laravel-Administrator

An administrative interface package for Laravel
http://administrator.frozennode.com/
MIT License
1.94k stars 503 forks source link

Error #2

Closed ceesvanegmond closed 11 years ago

ceesvanegmond commented 11 years ago

Hello there,

I constantly get the following error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM contacts WHERE id = ? LIMIT 1' at line 1

SQL: SELECT FROM contacts WHERE id = ? LIMIT 1

Bindings: array ( 0 => false, )

I simply have installed the bundle, created an 'admin' folder in the models dir, created an file called contact.php in the new dir.

This is the config

'models' => array(
    'contact' => array(
        'title' => 'Contacten',
        'model' => 'Contact',
    ),
),

The Frontend itself is working properly.

Any idea how this is come?

janhartigan commented 11 years ago

Hmmm not sure. Have you loaded the app/models/admin directory or namespace in your start.php? Is it telling you where in the code the error is occurring?

ceesvanegmond commented 11 years ago

Yes, i registered in the start.php Here is my stack trace:

Stack Trace:

0 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/laravel/database/connection.php(183): Laravel\Database\Connection->execute('SELECT FROM `c...', Array)

1 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/laravel/database/query.php(709): Laravel\Database\Connection->query('SELECT FROM`c...', Array)

2 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/laravel/database/eloquent/query.php(61): Laravel\Database\Query->get(Array)

3 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/laravel/database/eloquent/model.php(237): Laravel\Database\Eloquent\Query->first(Array)

4 [internal function]: Laravel\Database\Eloquent\Model->_find(false, Array)

5 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/laravel/database/eloquent/model.php(769): call_user_func_array(Array, Array)

6 [internal function]: Laravel\Database\Eloquent\Model->__call('find', Array)

7 [internal function]: AdminModels\Contact->find(false, Array)

8 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/laravel/database/eloquent/model.php(804): call_user_func_array(Array, Array)

9 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/bundles/administrator/libraries/modelhelper.php(67): Laravel\Database\Eloquent\Model::__callStatic('find', Array)

10 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/bundles/administrator/libraries/modelhelper.php(67): AdminModels\Contact::find(false, Array)

11 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/bundles/administrator/routes.php(113): Admin\Libraries\ModelHelper::getModel('contact')

12 [internal function]: Laravel\Bundle::{closure}(Object(Laravel\View))

13 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/laravel/event.php(199): call_user_func_array(Object(Closure), Array)

14 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/laravel/view.php(330): Laravel\Event::fire('laravel.composi...', Array)

15 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/laravel/view.php(427): Laravel\View->render()

16 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/laravel/view.php(352): Laravel\View->data()

17 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/laravel/blade.php(71): Laravel\View->get()

18 [internal function]: Laravel\Blade::Laravel{closure}(Object(Laravel\View))

19 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/laravel/event.php(199): call_user_func_array(Object(Closure), Array)

20 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/laravel/event.php(138): Laravel\Event::fire('laravel.view.en...', Array, true)

21 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/laravel/view.php(337): Laravel\Event::until('laravel.view.en...', Array)

22 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/laravel/view.php(570): Laravel\View->render()

23 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/laravel/response.php(246): Laravel\View->__toString()

24 /Users/ceesvanegmond/Sites/vigics/trunk/laravel/laravel/laravel.php(178): Laravel\Response->render()

25 /Users/ceesvanegmond/Sites/vigics/trunk/public_html/index.php(34): require('/Users/ceesvane...')

janhartigan commented 11 years ago

Ah ok that helps narrow it down. Do you have any fields defined in the contacts table? Could you share what that table looks like? Also could you show me what's in your contact.php model?

ceesvanegmond commented 11 years ago

The table itself:

id -> primary_key name, varchar email, varchar phone, varchar sortorder int

The eloquent class:

<?php

class Contact extends Eloquent {

public static $table = 'contacts';

}

The admin

<?php namespace AdminModels;

class Contact extends \Contact {

}

janhartigan commented 11 years ago

Alright right off the bat I can tell you that $columns, $filters, and $edit properties on your model are required (check the docs). This particular problem is happening because you have no $columns defined. Think about it like this: in order to determine how to make that SQL statement, the Administrator code needs some point of reference, which in my code is the $columns property. Without that, it's searching in the dark. As you might be able to tell, I need to throw some Exceptions in case people run into this sort of thing again by accident.

Please add those $columns, $edit, and $filters properties and let me know if it works!

In a future release (like...within a week or so), I plan on allowing for empty $filters and $edit properties. At the moment I don't know if there's a cross-driver way to get a table's columns without there already being some data in the table. Blank Eloquent objects don't have any attributes, and so it makes it difficult to do anything unless you define the $columns you want to show up in your administrative table. Because of that, for the foreseeable future, you will always have to define the $columns array in your model.

Read the docs for more info!

ceesvanegmond commented 11 years ago

Ah, that works! Thank you! Awesome! Maybe an idea to work out, to order the records by draging them with jQuery UI Draggable!

janhartigan commented 11 years ago

Awesome, glad it's working! That's definitely an interesting idea. I will try to think of a good way to put that in!