thiagocardoso
2 years ago

Non-static method Eloquent\Model::fill() should not be called statically error

Posted 2 years ago by thiagocardoso

Hi everybody! I'm trying to get a device info saved into my database but I'm getting an error which says: Non-static method Illuminate\Database\Eloquent\Model::fill() should not be called statically"

Here is the Model code:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Placa extends Model
{
    protected $fillable = ['part_number', 'alias', 'user_id'];
}

And here is the controller code:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Placa;

class AppController extends Controller {
    public function postDevices(Request $request){
        $inputs = $request->all();
        $placa = Placa::fill($inputs);
        return $placa;
    }
}

A sidenote is that all fields inside request matches the table fields, therefore the fill method,

Why I'm still getting this error?

Complete error:

ErrorException in AppController.php line 34:
Non-static method Illuminate\Database\Eloquent\Model::fill() should not be called statically
in AppController.php line 34
at HandleExceptions->handleError('8192', 'Non-static method Illuminate\Database\Eloquent\Model::fill() should not be called statically', '/home/thiago/Projects/sia/app/Http/Controllers/AppController.php', '34', array('request' => object(Request), 'inputs' => array('_token' => 'OvcZCL8xCYJGRjuNhGwshizjTCItcPm21JzIic21', 'part_number' => 'testecod', 'alias' => 'testenome', 'user_id' => '1'))) in AppController.php line 34
at AppController->postDevices(object(Request))
at call_user_func_array(array(object(AppController), 'postDevices'), array(object(Request))) in Controller.php line 55
at Controller->callAction('postDevices', array(object(Request))) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(AppController), 'postDevices') in Route.php line 189
at Route->runController() in Route.php line 144
at Route->run(object(Request)) in Router.php line 653
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 65
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 655
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 629
at Router->dispatchToRoute(object(Request)) in Router.php line 607
at Router->dispatch(object(Request)) in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 150
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 53
at require_once('/home/thiago/Projects/sia/public/index.php') in server.php line 21

Please sign in or create an account to participate in this conversation.