lundi 23 août 2021

Google Drive : File Uploading and Accessing the files

Can anyone help me the google drive [long term validity] refresh token,

  1. Refresh token getting expired every week, we wanted to fix and the refresh token permanently.
  2. Google project status is internal,application status
  3. using Laravel package : nao-pon/flysystem-google-drive
  4. Using Laravel Application.

Please Help me through this, Thanks in Advance.



via Chebli Mohamed

dimanche 22 août 2021

Trying to get property 'id_pembelian' of non-object

I want to retrieve data from the database without using foreach, in some articles I read just use first() to get the value from the database, but when I try I always get an error like the following: ErrorException Trying to get property 'id_belian' of non-object

can anyone help me?

this is my controller code :

 /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $isValid = $request->validate([
            'total_bayar' => 'required|integer'
        ]);


        // megambil total yang sudah di bayar
        $terbayar = Pembayaran::select('total_bayar')->where('id',$id)->first();

        // mengambil id pembelian dari tabel pembayaran
        $id_data_bayar = Pembayaran::select('id_pembelian')->where('id',$id)->first();

        // ambil data jumlah yang harus di bayar dari tabel pembelian
        $harga_bayar = Pembelian::select('total_harga')->where('id',$id_data_bayar->id_pembelian)->first();

        $total_akan_terbayar = $terbayar->total_bayar + $request->get('total_bayar');  

        if($isValid){
            if(($harga_bayar->total_harga != $terbayar->total_bayar) && ($harga_bayar->total_harga > $total_akan_terbayar)){
                $data = [
                    'total_bayar'=> $request->get('total_bayar'),
                    'updated_at' => Carbon::now(),
                    'status' => 'cicil'
                ];
                $isSaved = Pembayaran::where('id',$id)->update($data);
                if($isSaved){
                    return Redirect::to('/pembayaran/'.$id.'/edit')->with('warning','Transaksi Anda Sebesar Rp.'.$total_akan_terbayar.' Berhasil dicatat');
                }else{
                    return Redirect::to('/pembayaran/'.$id.'/edit')->with('error','Transaksi Anda Gagal dicatat');
                }
            } elseif(($harga_bayar->total_harga != $terbayar->total_bayar) && ($harga_bayar->total_harga == $total_akan_terbayar)) {
                $data = [
                    'total_bayar'=> $request->get('total_bayar'),
                    'updated_at' => Carbon::now(),
                    'status' => 'lunas'
                ];
                $isSaved = Pembayaran::where('id',$id)->update($data);
                if($isSaved){
                    return Redirect::to('/pembayaran/'.$id.'/edit')->with('warning','Transaksi Anda Sebesar Rp.'.$total_akan_terbayar.' Berhasil dicatat');
                }else{
                    return Redirect::to('/pembayaran/'.$id.'/edit')->with('error','Transaksi Anda Gagal dicatat');
                }
            } elseif(($harga_bayar->total_harga != $terbayar->total_bayar) && ($harga_bayar->total_harga < $total_akan_terbayar)) {
                return Redirect::to('/pembayaran/'.$id.'/edit')->with('warning','Jumlah yang anda masukan berlebih Rp.'.($total_akan_terbayar-$harga_bayar->total_harga));
            } else {
                return Redirect::to('/pembayaran/'.$id.'/edit')->with('error','Transaksi Anda Gagal dicatat');
            }
        }else{
            return Redirect::to('/pembayaran/'.$id.'/edit')->with('error','Transaksi Anda Gagal dicatat');
        }
    }


via Chebli Mohamed

i Faced this problem when i configure Firebase?

step 1: This is my controller code. firebase file and firebase DB are connected properly. but when run in postman i got 500 error but I am new on firebase show I don't know how can I resolved this

 public function ride_confirm(Request $request)
{
    $input = $request->all();
    $validator = Validator::make($input, [
        'km' => 'required',
        'vehicle_type' => 'required',
        'customer_id' => 'required',
        'promo' => 'required',
        'country_id' => 'required',
        'pickup_address' => 'required',
        'pickup_date' => 'required',
        'pickup_lat' => 'required',
        'pickup_lng' => 'required',
        'trip_type' => 'required'
    ]);
    if ($validator->fails()) {
        return $this->sendError($validator->errors());
    }
    
    $input['pickup_date'] = date("Y-m-d H:i:s", strtotime($input['pickup_date']));
    $current_date = $this->get_date($input['country_id']);
    $interval_time = $this->date_difference($input['pickup_date'],$current_date);
    if($interval_time <= 30){
        $input['booking_type'] = 1;
        $input['status'] = 1;
    }else{
        $input['booking_type'] = 2;
        $input['status'] = 2;
    }
    $factory = (new Factory)->withServiceAccount(config_path().'/'.env('FIREBASE_FILE'));
    $factory = (new Factory())->withDatabaseUri(env('FIREBASE_DB'));
    
    $database = $factory->createDatabase();
    
    $drivers = $database->getReference('/vehicles/'.$input['vehicle_type'])
                 ->getSnapshot()->getValue();
}

I faced this error when I run this code ... enter image description here



via Chebli Mohamed

Does Django need more resources of a server than Laravel? If the both are the same kind of application

Suppose I want to build a social Media Platform Website and App with API.

Then which will be less resource-hungry between Django and Laravel ?

Which framework can perform faster for the application in a same config server? and why ?

Thanks in Advance



via Chebli Mohamed

samedi 21 août 2021

add space after the third number except the last four numbers

I'm new to Laravel, and I've a small issue which is that i have column in DB that should store 13 numbers in specific form. The form is to add space after each 3 numbers except the last four numbers.

For Example: 1234567891234 it should stored in the following format: 123 456 789 1234

Thanks



via Chebli Mohamed

How to post lots of data to laravel database

please i am trying to submit this date to a database in laravel...i want to submit all same time, this is just two rows but i want even if it gets to 10 rows i can submit.

0: {item: "Electronics", subitem: "Laptop", subitem2: "Hard D", unit: "Length - meter (m)"}
1: {item: "Electronics", subitem: "Laptop", subitem2: "Hard D", unit: "Length - meter (m)"}

What i have tried

 for ($i = 1; $i < count($request->item); $i++) {
          
        }

I tried to do a for loop using the above code but its not working..got the below error

count(): Parameter must be an array or an object that implements Countable



via Chebli Mohamed

http://localhost:4200 has been blocked by CORS policy: Response to preflight request doesn't pass access control check

I have a laravel and angular app when i run angular app i'm getting following error:

Access to XMLHttpRequest at 'http://localhost/project/public/api/register' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I already have CORS middleware:

<?php

namespace App\Http\Middleware;

use Closure;

class CORS
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $response = $next($request);

        $response->header('Access-Control-Allow-Origin', '*');
        $response->header('Access-Control-Allow-Methods', '*');
        $response->header('Access-Control-Allow-Headers', 'X-Requested-With,Content-Type,X-Auth-Token,Origin,Authorization,Accept');
        //Access-Control-Allow-Credentials true or false
        return $response;
    }
}

Kernel:

 protected $middleware = [
        \App\Http\Middleware\TrustProxies::class,
        \App\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
        \App\Http\Middleware\CORS::class
    ];


via Chebli Mohamed