Snipe-it: Error on creating asset with custom fields

Created on 15 Apr 2016  路  14Comments  路  Source: snipe/snipe-it

When I'm creating an asset that I've established before that has custom fields, it appears an
Server Error: 500 (Internal Server Error).
If I remove the custom fields to the model, and then I create the asset, it has no issue, but I don't want to do all this steps when creating a new asset with every model.

Any clue what could it be?


Actual Behavior

(what actually happens goes here)


Please confirm you have done the following before posting your bug report:


Please provide answers to these questions before posting your bug report:

  • Version of Snipe-IT you're running
  • What OS and web server you're running Snipe-IT on
  • What method you used to install Snipe-IT (install.sh, manual installation, docker, etc)
  • If you're getting an error in your browser, include that error
  • What specific Snipe-IT page you're on, and what specific element you're interacting with to trigger the error
  • If a stacktrace is provided in the error, include that too.
  • Any errors that appear in your browser's error console.
  • Confirm whether the error is reproduceable on the demo.
  • Include any additional information you can find in app/storage/logs and your webserver's logs.
  • Include what you've done so far in the installation, and if you got any error messages along the way.
  • Indicate whether or not you've manually edited any data directly in the database

Most helpful comment

It worked then?

All 14 comments

Please provide us with the information requested at the Getting Help documentation: http://docs.snipeitapp.com/getting-help.html

Snipe-IT Version: (v2.1.0-8)
CentOS release 6.7 with Apache/2.2.15

Manual installation

ErrorException (E_RECOVERABLE_ERROR)

Argument 1 passed to Illuminate\Database\Eloquent\Relations\BelongsTo::associate() must be an instance of Illuminate\Database\Eloquent\Model, null given, called in /var/www/html/snipeit/app/controllers/admin/AssetsController.php on line 104 and defined

    /**
     * Associate the model instance to the given parent.
     *
     * @param  \Illuminate\Database\Eloquent\Model  $model
     * @return \Illuminate\Database\Eloquent\Model
     */
    public function associate(Model $model)
    {
        $this->parent->setAttribute($this->foreignKey, $model->getAttribute($this->otherKey));

Page: http://xx.xx.xx.xx/hardware/create
The error doesnt happen in the demo version


[2016-04-14 19:09:46] production.ERROR: exception 'ErrorException' with message 'Argument 1 passed to Illuminate\Database\Eloquent\Relations\BelongsTo::associate() must be an instance of Illuminate\Database\Eloquent\Model, null given, called in /var/www/html/snipeit/app/controllers/admin/AssetsController.php on line 104 and defined' in /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php:203
Stack trace:

0 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php(203): Illuminate\Exception\Handler->handleError(4096, 'Argument 1 pass...', '/var/www/html/s...', 203, Array)

1 /var/www/html/snipeit/app/controllers/admin/AssetsController.php(104): Illuminate\Database\Eloquent\Relations\BelongsTo->associate(NULL)

2 [internal function]: Controllers\Admin\AssetsController->postCreate()

3 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(231): call_user_func_array(Array, Array)

4 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(93): Illuminate\Routing\Controller->callAction('postCreate', Array)

5 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(62): Illuminate\Routing\ControllerDispatcher->call(Object(Controllers\Admin\AssetsController), Object(Illuminate\Routing\Route), 'postCreate')

6 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Routing/Router.php(967): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'Controllers\Adm...', 'postCreate')

7 [internal function]: Illuminate\Routing\Router->Illuminate\Routing{closure}()

8 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Routing/Route.php(109): call_user_func_array(Object(Closure), Array)

9 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1033): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))

10 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1001): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))

11 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(775): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))

12 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(745): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))

13 /var/www/html/snipeit/vendor/barryvdh/laravel-debugbar/src/Middleware/Stack.php(34): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)

14 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Session/Middleware.php(72): Barryvdh\Debugbar\Middleware\Stack->handle(Object(Illuminate\Http\Request), 1, true)

15 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)

16 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)

17 /var/www/html/snipeit/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)

18 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(641): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))

19 /var/www/html/snipeit/public/index.php(49): Illuminate\Foundation\Application->run()

#20 {main} [] []

I havent alter anything on the db on my own.

Hope this is enough ;) please let me know

Please tell me if there are any browser console errors, per the getting help documentation.

Solicitud desde otro origen bloqueada: la pol铆tica de mismo origen impide leer el recurso remoto en http://10.10.60.12//hardware/models/57/custom_fields?_token=geGktyqlnotCNk0cIzHvpSbhCKNxeNBTLWI4OnEK (raz贸n: falta la cabecera CORS 'Access-Control-Allow-Origin').

This is the error that appears when I select the model (that has the custom field) but the custom fields are not shown.

My browser is mozilla and it is on spanish .... do you need to turn back my browser to english?

No, it's complaining about a CORS policy mismatch. This usually happens when your url set in app/config/production/app.php doesn't match your actual URL. Can you tell me what you have for your url in app/config/production/app.php?

(And also tell me what the actual URL in your browser is for the create page)

'url' => 'http://10.10.60.12/' (my private ip)

My URL when creating the asset is
http://XX.XX.XX.XX:8083/hardware/create (it has an public IP address, cause I need to access from the internet)

And ..... XX.XX.XX.XX is different from 10.10.60.12 of course ;)

That's your problem. That URL in your app/config/production/app.php needs to match the URL you're accessing the site from. Fix that, and you should be all set.

(Also, no trailing slash on the URL in app/config/production/app.php)

You're awesome!!!!
Thanks!!! :)

It worked then?

Yes!
It is so beautiful now :)

Excellent, glad you got it sorted.

1237811519_chuck-norris-approves

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Rungea96 picture Rungea96  路  4Comments

ericdude101 picture ericdude101  路  5Comments

sopheaouk picture sopheaouk  路  3Comments

memtech3 picture memtech3  路  4Comments

comisso picture comisso  路  4Comments