vendredi 27 octobre 2023

What is the optimised way to fetch all items and related name, email from parent table using mysql query?

Suppose we have a table of order consisting of order IDs, what would be considered 'best practice' in terms of fetching all item data with their order?

Order table:
--------

| id | name | email |  phone | event_id |
|---- |------| -----|-----| -----|
| 1    | Anish  | anish@gmail.com | 8233472332| 1765 |
| 2    | ABC    | abc@gmail.com   | 784472332| 1765 |
| 3    | XYZ    | xyz@gmail.com   | 646322332| 1525 |

items table:
------------


| id | order_id | category |  qty | price |
|---- |------| -----|-----| -----|
| 1    | 1  | person 1 | 2| 299 |
| 2    | 1    | person 2   | 1| 399 |
| 3    | 2    | person 1   | 1| 299 |

I want to fetch all items and their order name, email, phone in a single query.

Expected result

| name | email | category |  qty | price |
|---- |------| -----------|----- | ----- |
|  Anish   | anish@gmail.com   | person 1 | 2| 299 |
| Anish    | anish@gmail.com.  | person 2   | 1| 399 |
| ABC      | abc@gmail.com     | person 1   | 1| 299 |

One to many relations Orders -> items (It has multiple rows related to a single order)

I want to display all items for an event (example: event id - 1765) along with name, email, and phone. Please suggest to me the optimized mysql query for the same. I am using Laravel 5.2.



via Chebli Mohamed

lundi 23 octobre 2023

I have error while i copy laravel project from shared hosting to local

I want to copy laravel from shared hosting into my computer and run it from xampp server this is my road:

  1. i'm compress public_html folder from host
  2. download it and extract in xampp/htacess/project_name directory
  3. i was export database from server and import in local phpmyadmin
  4. delete vender directory and run composer install
  5. edit config/database.php with my local database information
  6. edit .env file with local information after all i run php artisan serve and i get this error screenshot avilable up there does anybody can help me

enter image description here



via Chebli Mohamed

vendredi 20 octobre 2023

socketlabs not working without plainTextBody

This is working fine but when I am sending without plainTextBody then its not working I need to use without plainTextBody, I need to set just subject and htmlBody .

When I am working without plainTextBody then its not working.

$message->subject = "Simple Html file with text";
$message->plainTextBody = "This is the Plain Text Body of my message.";
$message->from = new EmailAddress("from@example.com");
$message->addToAddress(new EmailAddress("recipient1@example.com", "Recipient #1"));

//Get html content from a file
$pathToHtmlFile = __DIR__ .'../../../ExampleCode/Html/SampleEmail.html'; 
$message->htmlBody = file_get_contents($pathToHtmlFile);
 
//Send the message
$response = $client->send($message);

I am using this one https://www.socketlabs.com/api/ but I do not want to use plainTextBody in our project.



via Chebli Mohamed

lundi 16 octobre 2023

i tired search in google, GPT even Bard nothing change in this code, laravel 5 problem

so i have this code in laravel 5

Customer::where('type', 1)->join('tb_customer_connector', 'tb_contact.id_customer', '=', 'tb_customer_connector.id_customer')
        ->join('tb_technology_tag', 'tb_customer_connector.id_product', '=', 'tb_technology_tag.id')
        ->where('tb_technology_tag.about', $id)
        ->get();

and simply this code i use for make a tabbar that make a fillter based on the technology.about but if a customer have two technology with same about it will make the customer show duoble because duoble connector

duplicate customer image

i already use district and groupBy and other but nothing changes



via Chebli Mohamed

vendredi 13 octobre 2023

How to implement automatic code mapping UML in PHP

How to implement automatic code mapping UML in PHP. guide me which tool is perfect for us. My project running in Laravel 5.6, and I want to Codemapping all the code, So please suggest me solution.

How to implement automatic code mapping UML in PHP



via Chebli Mohamed

jeudi 12 octobre 2023

How can loop and display studentId accoirding to the course_code

I want to display the students ID according to the batchId in table view. example for how I want.

EN01              EN02
12335             58965
45624             78956
46325             78599

This is my controller function.

if($request->courseId!="" && $request->batchId!="")
        {
            $courseCodes = batches::where('course_id','=', $request->courseId)->where('id','=',$request->batchId)->get();
        }else{
            $courseCodes = batches::where('course_id','=', $request->courseId)->get();
        }


        $course = courses::where('course_active','Yes')->where('course_active_flag','1')->get();
        $users = User::all();

        $tabliView = "";

        $studentData = DB::table('students')
            ->select('studentId', 'batchId','courseId')
            ->where('courseId', $request->courseId);

        if ($request->batchId != "") {
            $studentData->where('batchId', $request->batchId);
        }

        $studentData = $studentData->get();

And This is my table view with loop

<table class="table table-bordered text-nowrap border-bottom" id="basic-datatable">
                                        <thead>
                                            <tr>
                                                @foreach ($courseCode as $couscode)
                                                    <th class="wd-15p border-bottom-0"></th>
                                                @endforeach
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @foreach ($studentData as $student)
                                                <tr>
                                                    @foreach ($courseCodes as $courseCode)
                                                        <td>
                                                            
                                                            @if ($student->batchId === $courseCode->id)
                                                                
                                                            @endif
                                                        </td>
                                                    @endforeach
                                                </tr>
                                            @endforeach
                                        </tbody>
                                </table>

Now the result is coming like each course code same student Id is printing but each course code has a unique batchId. Please help me to fix this issue.



via Chebli Mohamed

mardi 10 octobre 2023

Laravel (5.8) observer deleted is not working

I am using Laravel (5.8) and I need to delete a record from table A and then also table B. So I tried Observers, but it never fired the observer's deleted method.

I already used other methods like updating or updated, so I don't know why the deleted method is not firing.
I don't use soft delete, because I didn't make this database schema and I don't have authorities to modify that. But based on what I read from the document, it doesn't matter..right?

Here are my code.

  • Pay Controller.php
public function delete(Request $request, $idx){
    $payData = PaymentData::where('idx', $idx)->delete();
    return response()->json(['status' => true]);
}
  • PayObserver.php
public function deleted(PaymentData $paymentData)
{
        if ($paymentData->pay_type == "PA") {
            $app = AppData::where('oid', $paymentData->oid)->first();

            if (!empty($app)) {
                $app->delete();
            }
        }
}
  • AppServiceProvider.php
public function boot()
{
    \App\Models\PaymentData::observe(\App\Observers\PayObserver::class);
}

I also tried to add the observe statement to boot method in EventServiceProvider.php, but it wasn't working either.
I read the official document but couldn't find any clues..what did I miss?



via Chebli Mohamed