jeudi 2 septembre 2021

How to deploy laravel application on aws using ftp

I want to host my laravel application on AWS, i have my application on bitbucket i want to clone my application on aws i have

Host : X.XXX.XXX.X
user : XXXXX
pwd  : key file

and phpmyadmin details as well.

How can i clone my project on aws.

Thanks



via Chebli Mohamed

My Laravel application load time is very slow

My Laravel application loading time is in seconds not in milli-seconds how to I make it fast Can any one help it would be useful. Thanks in advance!

Image of the load time: Image of the load time



via Chebli Mohamed

Laravel Query Grouping

I just wanna ask if my approach is good? I have a api respopnse which a merchants where i want to do is that if merchants with the same group_id appeared more than once i will put it on a group of merchants then exclude all the merchants that part in a group in a merchants that appeared once only. I do here is that get the group_ids then loop through there and after fetching exclude the group_ids appeared more than once[enter image description here][1]

    $merchantsHaveGroupId = $merchants->whereNotNull('group_id')->get();
    
    $groupIds = $merchantsHaveGroupId->pluck('group_id')->toArray();
    $groupIds = array_count_values($groupIds);

    $numOfMerchantsToBeOnParent = 1;
    
    $listOfMerchantWillBeExcluded = [];
    $parentData = []; 
   
    foreach($groupIds as $key => $value){
        if($value > $numOfMerchantsToBeOnParent){
            $merchantGroupParent = MerchantGroup::find($key);
            $children = $merchantGroupParent->merchants()->whereIn('id',$ids);
            $childrenIds = $children->pluck('id')->toArray();
            $constructData = array(
                "id" => $key,
                "title" => $merchantGroupParent->title,
                "isParent" => true,
                "children_count" => $groupIds[$key],
                "children_merchants" => $children->get()->toArray(),
                "childrens_ids" => $childrenIds
            );
            array_push($parentData, $constructData);
            array_push($listOfMerchantWillBeExcluded, $key);
        }
    }

   
    // now exclude the found ids now part of a group
    $merchants = $merchants->whereNotIn('group_id',$listOfMerchantWillBeExcluded);
    
    $merchants = Merchant::sortRestaurants($merchants, $favorites, $cityautoassign);

 
    // for pagination
    $merchants = $merchants->toArray();

    // merge merchants
    if(!empty($parentData)){
        $merchants = array_merge($parentData,$merchants);
    }


via Chebli Mohamed

mercredi 1 septembre 2021

Laravel 5 using Intervention with Post Model

Hi I am not having much luck to try and use Intervention with an Image model. Really beginner to this, and have tried many many many changes to the code but not finding result, I have tried also to read online how to pass Intervention into model or model into Intervention but cannot find many information. I am trying only to add a watermark to uploaded images. The code works and image uploads but no watermark on image. Thank you for help! I include snippet of controller function (hope is enough). PostImage is model.

 $file_name = '';

   if ($request->hasFile('image')) {
       $post->has_image = 1;
       $file = $request->file('image');
       $file_name = md5(uniqid() . time()) . '.' . $file->getClientOriginalExtension();

       if ($file->storeAs('/posts/', $file_name)){
           $process = true;
       } else {
           $process = false;
       }
   }else{
       $process = true;
   }

   if ($process) {    
      if ($post->save()){
          if ($post->has_image == 1) {                                         
              $intervention_file = $file;
              $watermark = url('/assets/media/icons/socialbuttons/user.png');
                     
              $intervention = Image::make($intervention_file);
              $intervention->insert($watermark, 'bottom-right', 50, 50);
              $intervention->resize(400,400);
              $intervention->text('Hello, World', 50, 50, function($font){
                  $font->size(50);
                  $font->color("#ffb00");
                  $font->align('center');
                  $font->valign('top');
              });
              $intervention_file_name = md5(uniqid() . time()) . '.' . $intervention_file->getClientOriginalExtension();
              $intervention_file->storeAs('/posts/', $intervention_file_name);
                        
              if ($intervention->save()){
                 $post_image = new PostImage();
                 $post_image->image_path = $intervention_file_name;
                 $post_image->post_id = $post->id;                            
              }
                        
              if ($post_image->save()){
                  $response['code'] = 200;
              }


via Chebli Mohamed

how to handle null value in Laravel Eloquent?

i am new in laravel.Actually i want to filter some data on state and typeofsupply column. like if state="south australia" and typeofsupply="Inverter & Storage" then show me these rows who exist on both value.and if i filter like state="south australia" and typeofsupply=Nul.then these rows will be display who exist state of south australia and typeofsupply should be any of list(All type of supply)

public function show(Request $request){

    $typeofsupply='';
    $state='';
    if(!$request->all()==Null) {

        if(!$request->state==Null) {
            $state=$request->state;
        }
        if(!$request->typeofsupply==Null) {
            $typeofsupply=$request->typeofsupply;
        }

        $items = Postjob::where('state',$state)
                        ->where('typeofsupply',$typeofsupply)
                        ->get();
        dd($items);


via Chebli Mohamed

How to get 2 database tables and display only the 5 latest records? Laravel

I need to get the latest activity from the database and order them by created_at.

There is a database table of orders, which has a shop_id, and there is a database table of collected_birthdays, which also has a shop_id incommon.

How to get the latest orders and collected_birthdays which has the same shop_id and take 5 latest records?

The mission is to display to the user the latest records of the two database tables, in the future, there will be more tables which will I need to display and get the latest 5 records.

Currently I tried joining the tables, but it merges to one and the created_at value stays only from the one table.



via Chebli Mohamed

mardi 31 août 2021

Why isn't Laravel Dusk launching a browser window?

I am working on upgrading a Laravel application to 5.4 from 5.3 so I can use Laravel Dusk for testing. I have followed the official Laravel guide as well as this scotch.io tutorial and am not having any luck. Executing php artisan dusk produces the following output:

In Process.php line 1027:

  TTY mode is not supported on Windows platform.

Then the program exits. Is this preventing Dusk from launching a browser window?



via Chebli Mohamed