vendredi 4 août 2023

Invalid XSL format (or) file name when running php artisan commands on laravel 5.8

I'm getting the "Invalid XSL format (or) file name" error message when running php artisan commands, its only on my laravel 5.8 project, in others it runs perfectly

The command works but take way too long, occurs only in this project, anyone knows why is that?

I tried a feel solutions directly in the windows, but the commands works in others projects, so the problemn is in the project



via Chebli Mohamed

mercredi 2 août 2023

How to implement aws cloudfront in my laravel application?

Here is the code already used in my laravel application. This code directly get image url from my s3 storage. But I need to implement cloudfront and generate signed url for to get and download images.

foreach($fileInfos['files'] as $file) {
       $dlFileName = $file['name'];
       $fileDLUrls[] = FileIO::getUrl(FILE_ORIGINAL_DIRECTORY . '/'.$file['path'], $effectiveTime, ['ResponseContentType' => 
'application/octet-stream','ResponseContentDisposition' => 
'attachment; filename*=UTF-8\'\''. rawurlencode($dlFileName)]);
}
    public static function getUrl($fullPathName, $expires = '+1440 minutes', $headers = [])
    {
        if ($fullPathName == '') {
            return null;
        }

        switch (Storage::getDefaultDriver()) {
            case 's3':
                $disk = Storage::disk('s3');
                $headers = array_merge([
                    'Bucket' => env('AWS_S3_BUCKET'),
                    'Key' => $fullPathName
                ], $headers);
                $command = $disk->getDriver()
                    ->getAdapter()
                    ->getClient()
                    ->getCommand('getObject', $headers);
                $request = $disk->getDriver()
                    ->getAdapter()
                    ->getClient()
                    ->createPresignedRequest($command, $expires);
                return (string) $request->getUri();
            case 'local':
                return URL::to('/' . env('AWS_LOCAL_UPLOADDIR')) .
                         '/' . $fullPathName;
            default:
                return null;
        }
    }

I have changed above code as below,

public static function getUrl($fullPathName, $expires = '+1440 minutes', $headers = [])
    {
        if ($fullPathName == '') {
            return null;
        }


        switch (Storage::getDefaultDriver()) {
            case 's3':
                $resourceKey = env('CLOUDFRONT_URL').$fullPathName;
                $expired = strtotime($expires);
                $privateKey = env('AWS_PRIVATE_KEY');
                $keyPairId = env('AWS_KEY_PAIR_ID');
                
                $cloudFrontClient = new CloudFrontClient([
                    'profile' => 'default',
                    'version' => '2014-11-06',
                    'region' => env('AWS_REGION')
                ]);
                    $result = $cloudFrontClient->getSignedUrl([
                        'url' => $resourceKey,
                        'expires' => $expired,
                        'private_key' => $privateKey,
                        'key_pair_id' => $keyPairId,
                        
                    ]);
                    
                    return $result;
            case 'local':
                return URL::to('/' . env('AWS_LOCAL_UPLOADDIR')) .
                    '/' . $fullPathName;
            default:
                return null;
        }
    }

But I didn't use the headers in the first code. So that am not able to download the images. Can anyone help me to know about the reason or any solutions?



via Chebli Mohamed

mardi 25 juillet 2023

Class "App\Http\Controllers\User\Auth\Hash" no

I.m a noob @laravel, so i don't know what to do. its a password reset form that gives the error after the submit button is clicked.

Class "App\Http\Controllers\User\Auth\Hash" no

$user->password = Hash::make($request->password);

after receiving an otp code the user is redirected to this form to input new password but i get this error.

<?php

namespace App\Http\Controllers\User\Auth;

use App\Http\Controllers\Controller;
use App\Models\PasswordReset;
use App\Models\User;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Http\Request;
use Illuminate\Validation\Rules\Password;

class ResetPasswordController extends Controller {
    /*
    |--------------------------------------------------------------------------
    | Password Reset Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling password reset requests
    | and uses a simple trait to include this behavior. You're free to
    | explore this trait and override any methods you wish to tweak.
    |
    */

    use ResetsPasswords;


    public function __construct() {
        parent::__construct();
        $this->middleware('guest');
    }

    public function showResetForm(Request $request, $token = null) {

        $email = session('fpass_email');
        $token = session()->has('token') ? session('token') : $token;
        if (PasswordReset::where('token', $token)->where('email', $email)->count() != 1) {
            $notify[] = ['error', 'Invalid token'];
            return to_route('user.password.request')->withNotify($notify);
        }
        return view($this->activeTemplate . 'user.auth.passwords.reset')->with(
            ['token' => $token, 'email' => $email, 'pageTitle' => 'Reset Password']
        );
    }

    public function reset(Request $request) {

        session()->put('fpass_email', $request->email);
        $request->validate($this->rules(), $this->validationErrorMessages());
        $reset = PasswordReset::where('token', $request->token)->orderBy('created_at', 'desc')->first();
        if (!$reset) {
            $notify[] = ['error', 'Invalid verification code'];
            return to_route('user.login')->withNotify($notify);
        }

        $user = User::where('email', $reset->email)->first();
        $user->password = Hash::make($request->password);
        $user->save();

        $userIpInfo = getIpInfo();
        $userBrowser = osBrowser();
        notify($user, 'PASS_RESET_DONE', [
            'operating_system' => @$userBrowser['os_platform'],
            'browser' => @$userBrowser['browser'],
            'ip' => @$userIpInfo['ip'],
            'time' => @$userIpInfo['time']
        ], ['email']);


        $notify[] = ['success', 'Password changed successfully'];
        return to_route('user.login')->withNotify($notify);
    }


    /**
     * Get the password reset validation rules.
     *
     * @return array
     */
    protected function rules() {
        $passwordValidation = Password::min(6);
        $general = gs();
        if ($general->secure_password) {
            $passwordValidation = $passwordValidation->mixedCase()->numbers()->symbols()->uncompromised();
        }
        return [
            'token' => 'required',
            'email' => 'required|email',
            'password' => ['required', 'confirmed', $passwordValidation],
        ];
    }
}

expecting the password of the user to be changed



via Chebli Mohamed

lundi 24 juillet 2023

Sort an eloquent query based on the field of a nested model

I have this eloquent query that brings me 10 reports in a paginated manner with their respective transactions and contracts

            $reports = Report::with([
                "transaccions",
                "status_report",
                "contracts",
            ])
                ->where(function ($query) use ($filter, $dates, $type_report, $dataservice) {
                    $query
                        ->where("type_report", ($dataservice == 'true' ? '<>' : '='), $type_report)
                        ->whereBetween("created_at", [$dates[0], $fechas[count($dates) - 1]])
                        ->whereHas('status_report', function ($q) {
                            $q->whereIn("status", ["VERIFYED"]);
                        })
                        ->where(function ($query) use ($filter) {
                            $query->where("id", "like", '%' . $filter . '%')
                                ->orWhereHas('contracts', function ($query) use ($filter) {
                                    $query->where('contract', 'like', '%' . $filter . '%')
                                        ->orWhereHas("rif", function ($query) use ($filter) {
                                            $query->where("rif", 'like', '%' . $filter . '%');
                                        })
                                        ->orWhere("name", 'like', '%' . $filter . '%');
                                })->orWhereHas('transaccions', function ($query) use ($filter) {
                                    $query->where('ref', 'like', '%' . $filter . '%')
                                        ->orWhere('amount', 'like', '%' . $filter . '%');
                                });
                        });
                })
                ->paginate($length);

This query shows a result that is processed in another function and shows something like this

        {
            "id": 45751,
            "status": "VERIFYED",
            "type_report": "MENSUALITY",
            "nota": "",
            "transaccions": [
                {
                    "id": 46358,
                    "ref": "22380011359",
                    "voucher": false
                }
            ],
            "total": "1,28",
            "contracts": [
                {
                    "name": "PERSON",
                    "contract": "123456",
                    "rif": "1122334455",
                    "status": "ACTIVE"
                }
            ],
            "created_at": "2022-08-26 14:18:00"
        },

These results are displayed in a table and I would like to be able to sort the results based on transactions.amount, contracts.contract (or any other field from the nested models) but I can't find the way to do it, I know that you can order the nested models in this way:

             "transaccions" => function ($query) use ($order_by, $order) {
                    $query->orderBy($order_by, $order);
                },

but I need is to sort all the results, because that only sorts me the nested objects, thanks.



via Chebli Mohamed

vendredi 21 juillet 2023

Getting 429 Error on Creating Menu Items in Laravel 5.7

I was creating dynamic menu feature for my laravel site. When i create menus. It work fine. And when i create items in that menu then i get an error of 429. I could not resolve it after alot of research. This is my source code relevant to menu only.(https://github.com/qasimtariq101/test1/tree/main/)

Admin Side Menus Portions From where i can create multiple menus and then add items in each menu. On frontend i will choose different menus on different pages.



via Chebli Mohamed

mercredi 19 juillet 2023

How to delete record using where 2 conditions (AND) in Laravel?

When I do delete record in controller, laravel deletes condition one by one. Not two conditions at once. Has anyone experienced this issue? what's the solution?

can delete records for 2 conditions that have been determined, not delete records every single condition.



via Chebli Mohamed

Laravel specify channel in logger()->

I have this multiple channels in logging.php, want to specify the logger()->'s channel so that I can specify the log. I know Log::channel('channel name')-> but I want to use logger(). I'm using laravel 5.6



via Chebli Mohamed