#### Category : laravel-8

I have a datatable that fetches orders and is working and displaying properly. I show the orders to the users that initiated them. Then they can only search on their owns orders. Now I need to display a message to a user, if an order was found but it was initiated by another user, instead ..

I’m trying to take advantage of the Laravel’s Polymorphic Relationships I’m building an app where I have 3 tables: products, expenses and hunts. Each product, expense or hunt belongs to a category. I used to have 3 other different tables product_categories, expenses_categories and hunts_categories but I didn’t like doing it this way so I did ..

I’ve got a question to the laravel-notification-channels/webpush package. The basic functionality is given. I can send push notifications. But now it is the case that I do not always want to send to all subscribers, but only to selected ones. My setup looks like this: HasPushSubscriptions is integrated in the model Guest. But 1 Guest ..

This is my first attempt at Laravel and I got stuck trying to filter my data according to my drop down list. I have an index page where data for a vehicle log sheet is captured but I cant seem to figure out the MYSQL to filter it based on the dropdown item I pick. ..

I have been searching and searching and I cannot find an answer to this question. I need to make a query where I will have a dynamic number of OR clauses. The documentation seems to suggest it is possible to pass an array of conditions to either where or orWhere, and yet when I try ..

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 want to be able to call a boot method like the one shown below only after user has verified email. protected static function boot() { parent::boot(); static::created(function ($project) { // create row in another table }); } i want to insert a new row into another table only after user has verified email. so ..

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 ..

may I ask how to change the filename while storing files with FTP? Storage::(‘disk’)->put(‘folder/myPDF.pdf’, $file) The code above is storing my file as folder/myPDF.pdf/(myfile) but I want to put myPDF.pdf as my filename not folder, anyway I can solve it? Thanks in advance. Sourc.. 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}}" ..

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 ..

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 ..

So i have setup a docker container to run each of my laravel project, as well as a docker container with a MySQL database, this is because I have a few projects that run off the same database. I am able to successfully connect to the database through the app when pulling the apps up ..

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> ..

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 Normally when sending notifications in Laravel you send to a class with a Notifiable trait that defines "who" the notification is going to by the instance of the class. Such as with the User model. I have a use case to send a notification to myself (the admin) and I don’t have an entry in .. 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..

I have EmployeeController resource controller with given functions index, create, update, edit, show, store. How to add another new public function and do I need to define new route to direct request to that new added function ? Sourc..