#Posting cant find field even though it is in the database

8 messages · Page 1 of 1 (latest)

bleak venture
#
public function store(Request $request)
    {
        $item = new Asset();
        $item->asset_code = $request->input('Asset-Code');
        $item->serial_number = $request->input('Serial-Number');
        $item->description = $request->input('Description');
        $item->brand = $request->input('Brand');
        $item->mac_address = $request->input('Mac-Address');
        $item->save();
        
        return redirect()->route('items.index');
    }
fresh smelt
#

What exactly is the issue? Whats the error message?

glad ridge
#

Show us your table structure, and show us the exact column it's complaining about.
#rules 1

bleak venture
#

@fresh smelt @glad ridge

public function up(): void
    {
        Schema::create('assets', function (Blueprint $table) {
            $table->id('Asset-Code');
            $table->String('Serial-Number');
            $table->String('Description');
            $table->BigInteger('Brand')->unsigned();
            $table->foreign('Brand')->references('id')->on('brands');
            $table->String('Mac-Address')->nullable();
            $table->timestamps();
        });
    }
#

The error message "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'asset_code' in 'field list'" indicates that there is an issue with the column name 'asset_code' in your database table 'assets'. It seems that Laravel is trying to insert data into the 'assets' table but cannot find the 'asset_code' column."

wind crag
#

Your migration has Asset-Code, while you're setting asset_code on the model.
In all honesty, I'd recommend you to follow Laravel's best practices and its defaults. Such as calling the method $table->string() instead of $table->String(), naming columns serial_number instead of Serial-Number etc. Not to mention, Laravel would expect the primary key of a model to be id, which is also auto-incremented, you're setting a value on that, and you have named the column differently

bleak venture
wind crag