lundi 6 décembre 2021

Laravel command file output not updating

I updating Laravel command file.

File code updated on server but when I run command no changes in output.

how to update Laravel command file for new changes?



via Chebli Mohamed

Pass a laravel variable into a jquery array

I am trying to pass a variable into a jquery autocomplete script check this url (https://jsfiddle.net/duoc5bbh/1/) I found.

Laravel

@foreach($data as $value)
   
   
@endforeach

Jquery

$(function() {
  let users = [{
      "email": "marie@gmail.com",
      "name": "marie"
      }, 
      {
       "email": "miss@gmail.com",
       "name": "miss"
     }];
});

what I did

$(function() {
  let users = [{
      "email": ,
      "name": 
      }];
});

I am new in using laravel with jquery I need your help in this Thanks.



via Chebli Mohamed

Laravel route group and middlewares

i am working on a laravel project with users who can have status verified (email verified).

on the other hand, users can have a subscription which is verified by a "subscriptions" middleware.

So I have several groups of routes including 2 of which the only difference is the presence of subscription or not

group 1:

Route::group(['middleware' => ["auth:sanctum", "verified"]], function () {}

group 2

Route::group(['middleware' => ["auth:sanctum", "verified", "subscriptions"]], function () {}

my question is about the order laravel uses for routes in these groups. for example if the user satisfies all the middleware of the first group, does laravel test the middleware of the second? Does a user verified have a chance to enter the second group of routes with subscription?

conversely, if the user does not have a subscription, he will not pass the subscription middleware. but I have the impression that the user is redirected by the subscription middleware which fails while laravel could find the right route in the group without this middleware (group 1)

what I would like is that it just tests for the presence of a subscription and that if it does not find one it looks for the route in group1.

Does the order of the groups in the code have an impact on the processing?

thanks.



via Chebli Mohamed

dimanche 5 décembre 2021

Executing python file within another python file using Laravel

I'm currently calling the main python file in larval function, and inside that main python file I'm calling another 2 files ( PowerShell and sub python file) the problem is when the Laravel function is triggered it only call the main python file, however when I call the main python file using terminal all the files are executed like below:

Laravel function:

public function initialize(Request $request)
{
    $store_name = $request->get('store_name', 1);
    if (empty($store_name)) {
        return 'Missing store name';
    } else {
        $processes = File::get("/root/flask/android_api/processes.txt");
            File::put('/root/flask/android_api/url.txt', $store_name );
            $process = new Process(['python3.6', '/root/flask/android_api/buildAPK.py']);
            $process->run();
            if (!$process->isSuccessful()) {
                    throw new ProcessFailedException($process);
            } else {
                    return 'Starting the processes to build';
            }   
    } 
}

and within the main python file I have:

try:
    p = subprocess.Popen(["/usr/bin/pwsh", 
            "/root/flask/android_api/set_apk_builder.ps1", '-ExecutionPolicy',
                        'Unrestricted',
                        './buildxml.ps1'], 
            stdout=sys.stdout)
    p.communicate()

except:
    file = open ("/root/flask/android_api/log.txt", "w")
    file.write ("fail")
    file.close()


import slack
call(["python", "/root/flask/flask.py"])
os.system('python3.7 /root/flask/flask.py')


via Chebli Mohamed

samedi 4 décembre 2021

How to do user tracking for rollbar on laravel?

I did the laravel integration by following the document.

I have looked at the user tracking in this document, but it is not very descriptive. Can anyone help us?



via Chebli Mohamed

Catch an error while importing huge CSV in queue using laravel excel

I am using ShouldQueue method to have the large CSV into Queue but the errors of validations I am not able to catch them!

public function registerEvents(): array
{
    return [
        ImportFailed::class => function(ImportFailed $event) {
            dd($event); // This I will write into the FILE or send EMAIL but the job runs successfully but validation errors keep empty.
            $this->importedBy->notify(new ImportHasFailedNotification);
        },
    ];
}

My code looks like below

public function registerEvents(): array
    {
        return [
            ImportFailed::class => function(ImportFailed $event) {
            $filename = public_path('tmp').'/validation_error.txt';
            $myfile = fopen($filename, "w");
            fwrite($myfile, "domo");
            fclose($myfile);
            },
        ];
    }

I am in hope that if there is any error validation_error.txt file will have "Demo" inside it.

Also, I have crossed verify by removing ShouldQueue it gives me proper errors for email already exists a kind of.

Please help if you have any ideas! Thanks!



via Chebli Mohamed

vendredi 3 décembre 2021

How to do newline email body in laravel?

I want to send some information on mail body. When I try its works but Google shows trimmed content(...).

My code is like this:

$name = $e->name;
$code=$request->code;
 $mes2="loretmtext,";
        $mes3="loremtext";
        $mes4="Code:".$code;
        $mes5="e:".$name;
$mes6="text"


//and i send mail function
$msg= $mes2."<br />".$mes3."<br />".$mes4."<br />".$mes5."<br />".$mes6."<br />";

How can i solve?



via Chebli Mohamed