Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thiagocardoso's avatar

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

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
0 likes
3 replies
Snapey's avatar
Snapey
Best Answer
Level 122
    $placa = Placa::fill($inputs);

as the error says, fill is not a static method.

you could do;

    $placa = new Placa;
    $placa->fill($inputs);

but most people would use;


    $placa = Placa::create($inputs);

or, since it is pointless creating an input variable if you are just going to give it the entire request object;

    $placa = Placa::create($request->all());

or

    $placa = Placa::create($request->only(['part_number','alias','user_id']));

Just watch that $user_id You should not be passing it unchecked into the model as it could easily be faked to a different user

2 likes
thiagocardoso's avatar

Thank you very much Snapey. I thought that calling using the Placa::fill was the right way to call a function, and the 'Placa->something` was a way to access an attribute of the Model.

Now about the user_id security issue that you've mentioned, it's not a concern, because the field is filled by the system itself.

Thanks for the reply!

Skeinet's avatar

I have similar problem. I defined a Model I instantiated the model Now I try to change $casts but it doesn.'t works. Any idea?

$newModel= new DynamicModel; // works
$newModel->setTable('products'); // works
$newModel->setRules($product_rules_array); // works
$newModel->setCasts($product_casts_array); // !!! DOESN'T WORKS !!!
$newModel::find(12); // works


where DynamicModel is:

class DynamicModel extends Model
{
    protected static $_table;
	protected static $_rules;
	protected static $casts=[];
	protected $guarded=[];

	public $timestamps = true;

	public static function setCasts($csstsFromDB)
	{
		self::$casts = $csstsFromDB;
	}

	public function setTable($table)
	{
		static::$_table = $table;
	}

	public function setRules($rules)
	{
		static::$_rules = $rules;
	}
    
}

Please or to participate in this conversation.