Category : laravel-8

So I have this // Update transaction $transaction = Transaction::find($id); $transaction->total_price = $total_price; $transaction->last_edited_by = Auth::user()->name; $transaction->update(); // Update transaction_item foreach ($master_item_id as $key => $no) { $transaction = Transaction::find($id); $transaction->transcation_item->transaction_id= $transaction->id; $transaction->transaction_item->master_item_id = $no; $transaction->transaction_item->quantity = $quantity[$key]; $transaction->transaction_item->price = $price[$key][‘price’]; $transaction->transaction_item->update(); } My Model // Transaction Model public function transaction_item() { return $this->hasMany(TransactionItem::class, ‘transaction_id’); ..

Read more

I wanted to join table NotificationTypes with UserEnabledNotificationTypesId on the NotificationTypesId column of UserEnabledNotifications , only for the rows in which deleted_at column of NotificationTypes table is null. I’ve tried as below. But it is not sorting for the null value of deleted_at column in NotifocationTypes table. Any solutions? UserEnabledNotifications::with(‘userNotications’, function ($query){ $query->whereNull(‘deleted_at’); })->select(‘userId’,’notificationTypesId’)->get(); UserEnabledNotifications ..

Read more

I got a model called "Team" that uses a polymorphic relation called Invitation: Team /** * @return MorphMany */ public function invitations(): MorphMany { return $this->MorphMany(Invitation::class, ‘inviteable’); } Each Invitation belongsTo a Profile: Invitation /** * @return MorphTo */ public function inviteable(): MorphTo { return $this->morphTo(); } /** * @return BelongsTo */ public function profile(): ..

Read more

I have data display in view page and explode the mobile number but showing the error message. ErrorException Undefined offset: 1 – How to solve the issue. profile-edit.blade.php <form method="post" action="/profile-edit"> @csrf @php $member_mobile = explode(‘-‘,$data->profile_mobile_no); if($member_mobile[0]==”) $member_mobile_code=" "; if($member_mobile[1]==”) $member_mobile_no=" "; @endphp <div class="form-group">Mobile Number (with country code) <div class="input-group"> <input type="text" class="form-control" value="{{$member_mobile_code}}" ..

Read more

I have this foreach ($item_id as $key => $no) { $input[‘price’] = $price[$key][‘price’]; $input[‘quantity’] = $quantity[$key]; $subtotal[] = [$input[‘price’]*$input[‘quantity’]]; } $total_price = array_sum($subtotal); When I dd($total_price) it return 0. When I dd($subtotal) it return my array like this array:3 [▼ 0 => array:1 [▼ 0 => 3000000 ] 1 => array:1 [▼ 0 => 3 ..

Read more

See I can write some code in PHP I want to write the same code in laravel-8 how can I? My PHP code <td> <?PHP if($Runs>0 and $Balls==0){ echo $Runs*100; }elseif($Balls>0 and $Runs==0){ echo $Balls*$Runs; }elseif($Balls==0 and $Runs==0){ echo $Balls*$Runs; } elseif($Runs>0 and $Balls>=0){ echo $Runs/$Balls*100; } ?> </td> I want to write this same ..

Read more

Okay so I don’t know how to word my question, so excuse me if it doesn’t make sense My view @forelse ($transaction as $key=>$value) <tr> <td class="text-center">{{$key + 1}}</th> <td>{{$value->transaction_item->item->item_name}}</td> <td>{{$value->transaction_item->quantity}}</td> <td>{{$value->transaction_item->price}}</td> <td>{{$value->total_price}}</td> <td>{{$value->created_at}}</td> <td>{{$value->updated_at}}</td> <td>{{$value->last_updated_by}}</td> <tr> @endforelse My controller $transaction = Transaction::all(); return view(‘transaction.index’, compact(‘transaction’)); My model // Transaction protected $table = ‘transaction’; protected ..

Read more

My controller $this->validate($request, [ ‘master_item_id.*’ => [‘required’], ‘quantity.*’ => [‘required’, ‘numeric’, ‘gt:0’] ]); $master_item_id = array_map(‘intval’, $request->master_item_id); $quantity = array_map(‘intval’, $request->quantity); $price = MasterItem::whereIn(‘id’,$master_item_id)->get(‘price’); $transaction = Transaction::create([ ‘total_price’ => 1, ‘last_edited_by’ => Auth::user()->name ]); foreach ($master_item_id as $key => $no) { $input[‘transaction’] = $transaction->id; $input[‘master_item_id’] = $no; $input[‘quantity’] = $quantity[$key]; $input[‘price’] = $price[$key]; TransactionItem::create($input); } ..

Read more

I have my controller $this->validate($request, [ ‘master_item_id.*’ => [‘required’], ‘quantity.*’ => [‘required’, ‘numeric’, ‘gt:0’] ]); $master_item_id = $request->master_item_id; $quantity = $request->quantity; $price = MasterItem::whereIn(‘id’, $master_item_id)->get(‘price’); $transaction = Transaction::create([ ‘total_price’ => 1, ‘last_edited_by’ => Auth::user()->name ]); for ($i = 0; $i < count($master_item_id); $i++) { $data = [ ‘transaction_id’ => $transaction->id, ‘master_item_id’ => $master_item_id, ‘quantity’ => ..

Read more

Assume I have a the tables users and persons. An entry in persons can have a user id or not. So a person can have a user, but this is optional. This means that the foreign key in persons needs to be nullable. This is my database migration: $table->bigInteger(‘user_id’)->nulleable()->unsigned(); $table->foreign(‘user_id’)->nulleable()->references(‘id’)->on(‘users’); Sadly, when I check the ..

Read more

I just want to test an easy input field but I get this error! /** @test */ public function email_must_be_a_valid_email() { $response = $this->post(‘/api/contacts’, array_merge($this->data(), [’email’ => ‘NOT AN EMAIL’])); $response->assertSessionHasErrors(’email’); } private function data() { return [ ‘name’ => ‘Test Name’, ’email’ => ‘[email protected]’, ‘birthday’ => ’05/14/1988′, ‘company’ => ‘ABC String’ ]; } I ..

Read more

I want to create a blog where when I wreate a post a post can have 2 or more categories. I succed to do that with ONE category. Posts.php : <?php namespace AppModels; use AppEventsPostDeletedEvent; use AppEventsPostUpdatedEvent; use IlluminateDatabaseEloquentFactoriesHasFactory; use IlluminateDatabaseEloquentModel; use IlluminateDatabaseEloquentRelationsBelongsTo; use IlluminateDatabaseEloquentRelationsBelongsToMany; use AppModelsCategory; class Post extends Model { use HasFactory; protected ..

Read more

First of all sorry if my title question doesn’t make sense, since I don’t know how to word my problem and my English not that great. Okay, so I have my controller Buy::create([ ‘master_item_id’ => $request->master_item_id, ‘quantity_item’ => $request->quantity_item, ‘price’ => $request->price ]); I have my view <select id="master_item_id" name="master_item_id" class="form-control @error(‘master_item_id’) is-invalid @enderror"> <option></option> ..

Read more

I have a form that shows all the records in my database but I wish to have a dropdown list that would let me select a staff member and show all records for that member. my controller: public function reportcard() { $card= Subject::join(‘subject’, ‘reportcard.sub_id’, ‘=’, ‘subject.sub_id’) ->join(‘student’, ‘reportcard.student_key’, ‘=’, ‘student.student_key’) ->get(); $student = Student::get(); $subject ..

Read more

How can I send a notification without having to use the user model? public function SendSeguimiento(Request $request){ $toUser = Clientes::find(2); Notification::send($toUser, new Seguimiento($toUser)); // $pageName = ‘widgets’; return redirect()->route("clientes"); } i try to send a notification to the email of the table ‘Clientes’ in row 2 database: Error: help pls Sourc..

Read more