Eloquent creating empty record

I’m sure I’m doing something wrong but can’t figure out what it is. In a controller I have a method which executes: $estimate = Estimate::create( [‘session_id’ => ‘test’] ); Model: use HasFactory; protected $fillable = [‘width, height, direction_id, media_id, coating_id, shape_id, amount, qty, session_id’]; Estimate is related to estimates in my db. When triggered an… Read More Eloquent creating empty record

Why value is deleted after alert pop up says that it can not be deleted?

Hello i have made a dynamic add and remove input fields and the code works great except the part when you reach the maximum limit to delete fields, this is my code: function rmv() { var count = document.getElementsByTagName(‘input’); if(count.length > 6){ $(document).on(‘click’, ‘#rmvbtn’, function () { $(this).closest(‘#dynamic’).remove(); }); }else{ alert(‘Order must have minimum one… Read More Why value is deleted after alert pop up says that it can not be deleted?

How to retrieve casted date without toArray or toJson?

For formatting some date column via casts, for example: protected $casts = [ ‘deadline’ => ‘date:d/m/Y’, ]; when getting column, it’ll return carbon instance: dd($model->deadline); // Illuminate\Support\Carbon @1671235200 {#1542 ▶} But even when it’s casted to string, it won’t be formatted as specified in cast: dd( (string) $model->deadline ); // "2022-12-17 00:00:00" Just when I… Read More How to retrieve casted date without toArray or toJson?

Why the delete query execute Laravel

Hello i am trying to make a simple delete function but its showing an error This is the code from the controller: public function destroy($id) { $clientOrder = clientHasOrder::where(‘order_id’,$id)->firstOrFail(); $clientOrder->delete(); return redirect(‘/’)->with(‘msg’,’Order Deleted successfully!’); } This is the model code: class clientHasOrder extends Model { use HasFactory; public $timestamps = false; protected $fillable = [… Read More Why the delete query execute Laravel

can't use assign role to User where i give factory

I want to create users with factories and directly assign roles to them. However, I encountered an error while seeding. My Error was like there : Method Illuminate\Database\Eloquent\Collection::assignRole does not exist. Here is the code from my databaseSeeder.php : $user = User::factory(10)->create()->assignRole(‘Admin’); That is my UserFactory code. This is default, I dont change anithing: namespace… Read More can't use assign role to User where i give factory

How to update a single value with laravel

Hello i want to update a single value on another table using laravel. This is the code i have done until now but doesnt seem to work: $amount = Product::findorFail($request->products[$i]); $total_value = $request->amount[$i] + $amount->amount; $amount->update([‘amount’, $total_value]); dd($total_value); with dd i see that the result is correct but the update function is not, the query… Read More How to update a single value with laravel

How to pass a single value from controller to view Laravel

Hello i have made a function in my controller that generates random number and i want to pass that result number to the view. This is the code of the controller: public function create() { $randomNumber = random_int(100000, 999999); $clients = Client::all(); $products = Product::all(); return view(‘orders/create’,compact(‘clients’,’products’)) ->with($randomNumber,(request()->input(‘page’, 1) – 1) * 5); } I… Read More How to pass a single value from controller to view Laravel

PHP – How to increase asscociative array index inside foreach

My requested input is in $journal. It contains three arrays accounts_ledger_id, debit, credit and among which arrays are associative arrays. What do I want to input into two static arrays that have the same index at the associative level? Inside journal: array:4 [▼ "_token" => "y7euU2ocmiwCbni0o6JAtZINnnkmDf2pnfvt1Hvf" "accounts_ledger_id" => array:2 [▼ 0 => "1" 1 =>… Read More PHP – How to increase asscociative array index inside foreach