lundi 7 novembre 2022

Laravel 5.6: sending email to BCC without adding email in TO()

How to send email to only bcc() without to(). When I tried, I got error

Error Information.

URL: http://example.com Parameters: [] Request Name: Request Method: GET Line Number: 309 File: /var/www/html/project_name/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php Client IP: 127.0.0.1 HTTP Referer: Is Secure: Is Ajax: userAgent: Symfony content: Error Message: Whoops! There was an error. ErrorException (E_WARNING) Illegal string offset 'address' ErrorException thrown with message "Illegal string offset 'address'" Stacktrace: #38 ErrorException in /var/www/html/project_name/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php:309 #37 Illuminate\Foundation\Bootstrap\HandleExceptions:handleError in /var/www/html/project_name/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php:309

Sending email to all bcc without using to



via Chebli Mohamed

I want to get the list of users who were present in the club from 10 AM to 12 PM using an SQL query in Laravel eloquent

thank you for reading this issue. please help me with the below issue

I want to user list which users in the club at the time between

  • 022-11-07 11:32:48 - 2022-11-07 12:32:48

below is data store in DB

  • In Time--------------------Out Time----------------- be show in result

  • 2022-11-07 11:32:48 - 2022-11-07 12:32:48 => 1

  • 2022-11-07 10:32:48 - 2022-11-07 11:33:00 => 1

  • 2022-11-07 12:32:00 - 2022-11-07 13:32:00 => 1

  • 2022-11-07 11:45:00 - 2022-11-07 12:15:00 => 1

  • 2022-11-07 10:00:00 - 2022-11-07 13:00:00 => 1

  • 2022-11-07 09:30:00 - 2022-11-07 11:30:00 => 0

  • 2022-11-07 12:35:00 - 2022-11-07 13:32:48 => 0

$activity = Activity::findOrFail($activity_id);

$users = User::whereHas('activities', function ($q) use ($activity) {
   $q->where('activities.activity_id', $activity->activity_id);
})->whereHas('bookingActivities', function ($query) use ($booking) {
   $query->whereNull('cancelled_by')
   ->whereBetween('bookingActivities.entry_time', [$booking->entry_time, $booking->exit_time])
   ->orWhereBetween('bookingActivities.exit_time', [$booking->_entry_time, $booking->exit_time]);
})->paginate();

I have add the query and it will give me 4 result it Should be 5

please help me to how can i add the query so i can get expect result.

thanks in advance



via Chebli Mohamed

samedi 5 novembre 2022

Laravel Fatal error: Uncaught ReflectionException: Class App\Http\Kernel does not exist

Tried to install ** maatwebsite/excel** using composer as,

composer require maatwebsite/excel

but it throws Kernel does not exist error.

There are kernel files in the following locations

app\Console\Kernel.php app\Http\Kernel.php

Also tried composer update, composer dump-autoload. Tried deleting vendor folder and then composer install

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.3|^8.0",
        "fideloper/proxy": "^4.4",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "laravel/framework": "^8.12",
        "laravel/tinker": "^2.5",
        "laravel/ui": "^3.2",
        "maatwebsite/excel": "^3.1"
    },
    "require-dev": {
        "facade/ignition": "^2.5",
        "fakerphp/faker": "^1.9.1",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.2",
        "nunomaduro/collision": "^5.0",
        "phpunit/phpunit": "^9.3.3"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "platform-check": false
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

```
`

How do i resolve this issue.


via Chebli Mohamed

vendredi 4 novembre 2022

WhatsApp API integration in Laravel not working

I have issue in my laravel project, the code below is working fine in core php, but it's not workng in laravel

i'm using old laravel version 5.5

even not showing any error

please help me ASAP, i hava a deadline

please help me ASAP, i hava a deadline please help me ASAP, i hava a deadline

`if($request->has('whatsapp') && $request->whatsapp!=0){
                $url = "https://graph.facebook.com/v15.0/{key}/messages";

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('{auth key}', 'Content-Type: application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$data3 = [
  
    "type"=>"body",
    "parameters" => [
      "type"=>"text",
      "text" => "Mr Jibran"
    ]
];

$data2 = [
  "name"=>"sample_issue_resolution",
"language"=> ["code"=> "en_US" ],
"components" => $data3
];

/*
components:{
  type:body,
  parameters {
    type:text,
    text:Mr Jibran
  }}"

*/

$data = array(
  "messaging_product"=>"whatsapp",
  "to"=>"my number",
  "type"=>"template",
  "template"=> array(
    "name"=>"sample_issue_resolution",
    "language"=> array ("code"=> "en_US" ),
    "components" => array(
      ["type"=>"body",
    "parameters" => array(
      ["type"=>"text",
      "text" => "Mr Jibran"]
    )]
    )
  )
)
;



$fields_string = json_encode($data);

curl_setopt($curl, CURLOPT_POSTFIELDS, $fields_string);

$resp = curl_exec($curl);
curl_close($curl);

echo $resp;
                
            }

        }

    }`


via Chebli Mohamed

jeudi 3 novembre 2022

Instance class by some rule

I have some function converting some tag to class name.

function($tag): string {
    return '\App\Services\MyUglyServices\' . ucfirst(Str::camel($tag));
}

I want to instance some class by corresponding tag name. For example:

$obj = app('tag:my_ugly_service');
echo get_class($obj); // I want it to be \App\Services\MyUglyServices\MyUglyService

Is there any way to do it using service providers?



via Chebli Mohamed

mardi 1 novembre 2022

Laravel 5 User::where() My where call isn't working with laravel 5

I have narrowed my error down to this line of code

$user= User::where(['email'=>$req->email])->first();

it it not working with Laravel 5 I think this is from a Laravel 4 project. How do I update it to 5?



via Chebli Mohamed

Why my excel import date format is not working in laravel

I try to import the excel data file but my date format is not working. other than that data import is working file only issue is in the date format Please help to solve this issue.

enter image description here

this is my import code.

<?php

namespace App\Imports;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Carbon;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;

use App\student_import;

use App\centres;
use App\Course;

class ImportStudent implements ToModel,WithHeadingRow
{
    /**
    * @param Collection $collection
    */

    public function model(array $row)
    {
        $rowNumber = array_values($row);

        $insert_data[] = array(
            'stud_dob' => Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($rowNumber[8])),
            'stud_gender' => $rowNumber[9],
            'stud_add1' => $rowNumber[10],
            'stud_nationality' => $rowNumber[13],
            'stud_registration_date' => Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($rowNumber[14])),
            'stud_completion_date' => Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($rowNumber[15])),
            'stud_course_status' => $rowNumber[16]
        );

    }
}

This is the error I'm getting when import the data file

enter image description here

enter image description here



via Chebli Mohamed