Ad

Is There An Alternate Way To Use Findorfail() On Updating With Stored Procedures?

I'm getting an error :

"Call to undefined method Illuminate\Database\SqlServerConnection::find()"

I'm trying to update a table that was executed using stored procedure.

public function update(Request $request)
{
    $cont = DB::find($request->ContainerId);

    $cont->update($request->all());

    return back();
}

I wanted to update a record in SQL Server but no luck at all.

Ad

Answer

DB is in general an anti pattern in Laravel applications and the DB does not have a find method either, it has methods for raw SQL queries.

Instead utilize your model, use the static methods there (like find or findOrFail). The table name is generated from a pluralized version on the class name, so the table name should be containers

public class Container extends Model {
}

Container::find($request->ContainerId);
Ad
source: stackoverflow.com
Ad