I have problem with my database due to the capacity of the variable. So, I changed my id from integer to bigInteger as show below. id will be storing barcode number.
class CreateItemsTable extends Migration { public function up() { Schema::create('items', function (Blueprint $table) { $table->bigInteger('id')->unsigned(); $table->string('name',100); $table->decimal('buying_price', 5, 2); $table->timestamps(); }); } However, when I try to access the item table from other controller, the page shows this error
No query results for model [App\Item] 2147483647
This is how my controller looks like. I want to make my item_id for order equal to item->id.
public function store(Request $request) { $this->validate($request, [ 'item_id'=>'required|integer', 'quantity'=>'required|integer', ]); $item=Item::FindOrFail($request->item_id); $order=new Order; $order->status=$request->get('status'); $order->item_id=$item->id; if ($request->get('status')=='Complete') { $item->quantity += $request->input('quantity'); } $order->quantity=$request->input('quantity'); $order->save(); $item->save(); return redirect('/Order')->with('success','Order added'); } 82 Answers
The number 2,147,483,647 (or hexadecimal 7FFF,FFFF16) is the maximum positive value for a 32-bit signed binary integer in computing. It is therefore the maximum value for variables declared as integers (e.g., as int) in many programming languages.
You should change from INTEGER to VARCHAR in your DB to see if this fixes your error, if it does not, check your scripting language, there may be an operation that exceeds 2,147,483,647, therefore just showing its max.
Did you rolled back your migrations and migrated again? If your table is already created, you have to create a new migration, changing the wanted field
Schema::table('items', function (Blueprint $table) { $table->bigInteger('id')->unsigned()->change(); }); and then migrate again with
php artisan migrate BUT THIS ISN'T THE BEST THING TO DO
MySql has its methods of handling auto increments.
You can create big increments in laravel with
$table->bigIncrements('id'); See documentation for more information.
6