lundi 22 août 2022

Undefined array key "project" - work with api, cteating console command

I have code where I use function for get data from api getTimeEntriesInfo

    public function getTimeEntriesInfo(int $user_id): array
    {
        $users = self::getAllData('time_entry', ['user_id'=>$user_id]);
        return $users['time_entries'];
    }

Then I create console command artisan to save all data from api:

<?php

class LinkNew extends Command
{

    public function handle()
    {
        $redmineService = new RedmineAPIService();
        $users = $redmineService->getUsersInfo();

        foreach ($users as $user) {
            $data = $redmineService->getTimeEntriesInfo($user['id']);
            //dd($data);

            $project = $redmineService->getTimeEntriesInfo($user['project']);
            $activity = $redmineService->getTimeEntriesInfo($user['activity']);
            $issue = $redmineService->getTimeEntriesInfo($user['issue']);
            $comments = $redmineService->getTimeEntriesInfo($user['comments']);

            if ($this->confirm('Is this information correct?')) {
                $link = new TimeEntry();

                $link->project = $project;
                $link->activity = $activity;
                $link->issue = $issue;
                $link->comments = $comments;
                //dd($link->getAttributes());
                $link->save();

                $this->info("Saved.");
            }
        }
        return 0;
    }
}

But I have mistake Undefined array key "project". Why?

dd($data)

  248 => array:10 [
    "id" => 5379
    "project" => array:2 [ …2]
    "issue" => array:1 [ …1]
    "user" => array:2 [ …2]
    "activity" => array:2 [ …2]
    "hours" => 1.5
    "comments" => "Some comment"
    "spent_on" => "2022-05-27"
    "created_on" => "2022-05-27T09:31:18Z"
    "updated_on" => "2022-05-27T09:31:18Z"
  ]
  249 => array:10 [
    "id" => 5369
    "project" => array:2 [ …2]
    "issue" => array:1 [ …1]
    "user" => array:2 [ …2]
    "activity" => array:2 [ …2]
    "hours" => 1.0
    "comments" => "Some comment"
    "spent_on" => "2022-05-27"
    "created_on" => "2022-05-27T05:00:19Z"
    "updated_on" => "2022-05-27T05:00:19Z"
  ]

upd

    public function handle()
    {
        $redmineService = new RedmineAPIService();
        $users = $redmineService->getUsersInfo();
        foreach ($users as $user) {
            $data = $redmineService->getTimeEntriesInfo($user['id']);


            //isset($user);
            foreach ($users as $user) {
                //$data = $redmineService->getTimeEntriesInfo($user['id']);
                //dd($data);

                $project = $data['project'];
                $activity = $redmineService->getTimeEntriesInfo($data['activity']);
                $issue = $redmineService->getTimeEntriesInfo($data['issue']);
                $comments = $redmineService->getTimeEntriesInfo($user['comments']);

                if ($this->confirm('Is this information correct?')) {
                    $link = new TimeEntry();

                    $link->project = $project;
                    $link->activity = $activity;
                    $link->issue = $issue;
                    $link->comments = $comments;
                    //dd($link->getAttributes());
                    $link->save();

                    $this->info("Saved.");
                }
            }
        }

        return 0;
    }


via Chebli Mohamed

dimanche 21 août 2022

fetch maximum column row in laravel

I have this table structure

id |  user_id  |   sequence_id  |  test_id

1       11             1            4
2       11             3            4
3       11             9            4
4       11            10            4

..
..
20      11             18           4

i want to fetch the maximum sequence_id that exist for particular user, using this query

test::where('test_id', $request->id)->orderBy('sequence_id', 'DESC')->get();

but getting 9th sequence id but it should return 18

Any solution Thanks



via Chebli Mohamed

Exception in UI \ view in section that is in comment - HTML PHP Laravel

I have a question, and I am new to laravel and html. I have a view, and in the view I have a certain code that is in comment. when I try to load the page it throws exception on this part of code, But why? If I remove the code completely it worked, so why the page loads the comments?

this the code:

 <!--  <td> Removed in and not to use
                    <input type="text" class="table-control p-r-20" name="dsp_fee_pct" value="" id="dsp_fee_pct">
                    <span class="table-control-addon-right">%</span>
                </td> -->

and this is the exception: enter image description here



via Chebli Mohamed

vendredi 19 août 2022

Generate PDF with image from database with mPDF Laravel

I have an issue with a view and generated content to produce a PDF.At the moment, I've been working with mpdf\mpdf , but when i want to show the image on the view , error occurs .

My controller :

$view = View::share('data', $data);
$mpdf= new \Mpdf\Mpdf([
            'mode'=>'UTF-8','format' => [400, 400],'autoScriptToLang'=>true,'autoLangToFont'=>true
]);
$mpdf->WriteHTML(view('frontend.create-cv.pdf',compact('data')));

My blade :

<img src="/frontend/assets/images/cv/">


via Chebli Mohamed

Get specific values from same table after Group By

Hi pls check the below Query

SELECT * FROM order_has_status group by order_id order by order_id DESC;

query_result

I'm trying to get the marked orders_id



via Chebli Mohamed

jeudi 18 août 2022

How to prevent HTML resizing in PDF using mPDF and Laravel?

This is my original HTML page :

original HTML

And this the output of generated PDF :

generated PDF

In the parts marked with a red arrow in the last picture, the size of the elements decreases automatically . How can I prevent this?



via Chebli Mohamed

mercredi 17 août 2022

Laravel Eloquent Relationship query with whereHas retrieve data

I have the following models in my application(Laravel):

class City extends Model {
  public function travels(){
    return $this->belongsToMany('App\models\Travel');
  }
}

class Travel extends Model {
   public function cities(){
     return $this->belongsToMany('App\models\City');
   }
   public function deals(){
     return $this->hasMany('App\models\Deal');
   }
}

I have the following table layout:

cities:

  • id
  • name

travels:

  • id
  • description

city_travel:

  • id
  • city_id
  • travel_id

deals:

  • id
  • travel_id

Now I want to display all the names of the cities with the count of travels where have deals (I not only want the cities which have only travels but these travels must also have deals) I hope I have explained my need well.

I tried only to retrieve the cities that have travels, with the code below but I'm stuck here :

$cities = City::whereHas('travels')-get();

Thanks for your help!



via Chebli Mohamed