vendredi 3 décembre 2021

custom sound doesn't work using fcm in flutter

I am working with laravel as a server and flutter as a frontend, I am using fcm, I get the notifications but with the default android sound and I cannot make them custom. in flutter I create a file in main / res / raw / notification.wav and This is my code in laravel

public function toFcm($notifiable)
    {
        $message = new FcmMessage();
        $notification = [
            'title'        => "Nueva Orden #".$this->order->id." para ".$this->order->restaurant->name,
            'body'         => $this->order->user->name,
            'icon'         => $this->order->foodOrders[0]->food->restaurant->getFirstMediaUrl('image', 'thumb'),
            'sound'        => "notification",
            'click_action' => "FLUTTER_NOTIFICATION_CLICK",
            'id' => '1',
            'status' => 'done',
        ];
        $message->content($notification)->data($notification)->priority(FcmMessage::PRIORITY_HIGH);

        return $message;
    }


via Chebli Mohamed

Laravel constrain eager loading - apply limit if relationship column != 1

Am building a system that works similar to the popular flashcard software called "Anki" and am trying to eager load some answers that belong to a user study, but with some modifications.

Model relationships

  • User has many Study
  • Study has many Answer

Here is the code snippet. (Take a look at the second section below)

$user_query = User::with([
    'studies.answers' => function ( $query_answer ) use ( $args ) {
        $query_answer
            ->where( 'grade', '=', 'hold' )
            ->groupBy( 'card_id' )
            ->orderByDesc( 'id' );

            if ( $args['no_date_limit'] ) {
                $query_answer = $query_answer->where( 'next_due_at', '>', $args['start_date'] );
            } else {
                $query_answer = $query_answer->whereBetween( 'next_due_at', [ $args['start_date'], $args['end_date'] ] );
            }

            if ( ! empty( $args['card_ids_in'] ) ) {
                $query_answer = $query_answer->whereIn( 'card_id', $args['card_ids_in'] );
            }
            if ( ! empty( $args['card_ids_not_in'] ) ) {
                $query_answer = $query_answer->whereNotIn( 'card_id', $args['card_ids_not_in'] );
            }

Below, I want to apply the limit if study.answer_all_on_hold ($study_all_on_hold) != 1 And also read the $no_on_hold value from study.no_on_hold

            // Here, I want to apply the limit ($study_all_on_hold ) if study.answer_all_on_hold != 1
            if ( ! $study_all_on_hold ) {
                // And also read the $no_on_hold value from study.no_on_hold
                $query_answer = $query_answer->limit( $no_on_hold );
            }
        },
    ])
    ->where( 'ID', '=', $user_id );

As you can see am trying to apply the limit from the column value of the study. Is this currently possible ?



via Chebli Mohamed

jeudi 2 décembre 2021

How can I Update my app to theme app extensions in shopify

I want to update my app to a theme app extension and I am using backend laravel. For integrating Laravel with Shopify I am using oseintow/laravel-shopify addon in Laravel.



via Chebli Mohamed

how to compare number (0,1,2, -1, -1.5) and text values ​in php

I have a form to fill in the examination data. The form is filled in by a doctor, the data to be filled can also be numbers or text and I store this type of data in the table ex: 0 for numeric data types and 1 for text. when the form is saved, I will compare the data results with the specified standard value, so if the inspection result is greater than the standard value, it will produce a critical value or vice versa. for now I'm comparing the values ​​using the if else condition. is there a more efficient way than using the if else condition because the method I use currently still has bugs, ex: if the value is minus then the result that comes out doesn't match or if the text contains characters (+) or (-) then error result.

if( ($data_type== 0) || is_numeric($standart_value->MIN_VALUE) && is_numeric($standart_value->MAX_VALUE) ){

  if( ( floatval($v['result']) >= floatval($standart_value->MIN_VALUE) ) && ( floatval($v['result']) <= floatval($standart_value->MAX_VALUE) ) ){

    $is_normal = 1;

   }else{

    $is_normal = 0;

  }
  
}elseif( ($data_type== 1) || !is_numeric($standart_value->MIN_VALUE) && !is_numeric($standart_value->MAX_VALUE) ){

  $min = strtoupper($standart_value->MIN_VALUE);
  $max = strtoupper($standart_value->MAX_VALUE);
  $value = strtoupper($v['result']);

  if( ( preg_match_all("|$min|i", $value ) ) || ( preg_match_all("|$max|i", $value ) ) ){
                        
       $is_normal = 1;
         
  }else{
                        
       $is_normal = 0;
      
   }

}


via Chebli Mohamed

How can I skill the current php artisan serve session before start a new one?

I often find myself open uo so many port when running php artisan serve

Laravel development server started: <http://127.0.0.1:8000>
[Thu Dec  2 19:56:23 2021] Failed to listen on 127.0.0.1:8000 (reason: Address already in use)
Laravel development server started: <http://127.0.0.1:8001>
[Thu Dec  2 19:56:23 2021] Failed to listen on 127.0.0.1:8001 (reason: Address already in use)
Laravel development server started: <http://127.0.0.1:8002>
[Thu Dec  2 19:56:23 2021] Failed to listen on 127.0.0.1:8002 (reason: Address already in use)
Laravel development server started: <http://127.0.0.1:8003>

Is there away to kill http://127.0.0.1:8000 before starting a new one ?

so my application will be at http://127.0.0.1:8000...

Any hint for on how to do that ?



via Chebli Mohamed

Laravel Timezone doesn't convert to the correct timezone in Laravel

I am trying to build a simple function where I want to fetch a DateTime from database that is stored in UTC format and display it to the user in their local timezone. I found heaps of solutions that works, but the timezone is not correct.

 $time = Carbon::createFromFormat('Y-m-d H:i:s', $user->created_at)->settings(['timezone' => 'Australia/Sydney']);

So this code takes in $user->created_at , "created_at": "2021-12-02T21:18:31.000000Z", which in UTC format created on 21:18, which is 8:18 am in Sydney, yet, when I run the code i get a wrong time zone, "2021-12-02T10:27:29.000000Z", which is 10:27 am.

I am not sure whats happening. Any Help will be greatly appreciated



via Chebli Mohamed

The image that i uploaded in my post is diplaying broken image i dont know why it is not working i crate public/storage /posts folder using the cmds

i am using laravel 5.8 and the image that i uploaded is displaying in broken format the is here

 public function store(createpostrequest $request)
    {
        $image=$request->image->store('posts');
       $post = post::create([
            'title'=>$request->title,
            'description'=>$request->description,
            'content'=>$request->content,
            'image'=>$image,
            'published_at'=>$request->published_at,
            'catagory_id'=>$request->catagory
        ]);

       if ($request->tags) {
           $post->tags()->attach($request->tags);
       }

        //flashing the message

        session()->flash('success','Post created successfully');
        return redirect(route('posts.index'));
    }   

and in the post index page

                    ```
image)}}"> ``` but the image is that displaying in the page is broken when i remove the asset() it displays the image that is store in public/storage/post .........but i cant open this folder ........

via Chebli Mohamed