mercredi 26 août 2020

Laravel error when using composer to setup

I am a php beginner. I got some problem when using composer to initially extend the project. Your kindness would be highly appreciate.

Hereby is the trace infomation and composer.jason.

Stack trace: #0 C:\Users\jim\git\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php(809): ReflectionClass->__construct() #1 C:\Users\jim\git\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php(691): Illuminate\Container\Container->build() #2 C:\Users\jim\git\laravel\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(796): Illuminate\Container\Container->resolve() #3 C:\Users\jim\git\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php(269): Illuminate\Foundation\Application->resolve() #4 C:\Users\jim\git\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php(805): Illuminate\Container\Container->Illuminate\Container{closure}() #5 C:\Users\jim\git\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php(691): Illuminate\Container\Container- in C:\Users\jim\git\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 811 Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255


{ "name": "laravel/laravel", "type": "project", "description": "The Laravel Framework.", "keywords": [ "framework", "laravel" ], "license": "MIT", "require": { "php": "^7.2.5", "fideloper/proxy": "^4.2", "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": "^6.3", "laravel/framework": "^7.24", "laravel/tinker": "^2.0" }, "require-dev": { "facade/ignition": "^2.0", "fzaninotto/faker": "^1.9.1", "mockery/mockery": "^1.3.1", "nunomaduro/collision": "^4.1", "phpunit/phpunit": "^8.5" }, "config": { "optimize-autoloader": true, "preferred-install": "dist", "sort-packages": true }, "extra": { "laravel": { "dont-discover": [] } }, "autoload": { "psr-4": { "App\\": "app/" }, "classmap": [ "database/seeds", "database/factories" ] }, "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" ] } }


I try to track the exception and found error indicator in app.php



via Chebli Mohamed

issue laravel version 6.0 not able to call compact function

writing this code for routing

Route::get('/welcome', 'WelcomeController@welcome');

after that i have called to a new controller

<?php
    namespace  App\Http\Controllers;
    
    class WelcomeController extends Controller{
        
        public function welcome () {
            $data = ['name'=>'Test'];
            return view('welcome', compact(data));
        }
    }

after that i am calling this $data variable in welcome.blade.php

using this method $data['name'];

server not sending any responce



via Chebli Mohamed

Query fails when trying to get candidates from API with two words value separated by space

Both queries are not returning candidates with status:Returned Candidate. First query never fails but not returning candidates with status: Returned Candidate. Second query fails with error "Trying to get property of non-object". Please can you advise how this query should be built and how correctly request a status with two words value separated by space.

    $query = '&query=isDeleted:0 AND (status:Registered OR status:Returned Candidate OR status:Offer OR status:Placed OR status:Unavailable)';
    $query = '&query=isDeleted:0 AND (status:"Returned Candidate" OR status:"Offer" OR status:"Placed" OR status:"Unavailable")';



    $query = str_replace(" ", "%20", $query);
    $fields = 'id';
    $method='search/Candidate?BhRestToken='.Session::get('BH.restToken').$query.'&fields='.$fields.'&count='.$count.'&start='.$start.'&sort=-customDate1';

    $response = $bh->makeHttpRequest(Session::get('BH.restURL'), $method);


    if(isset($response->errorMessage)){

        if(BH_DEV === true) echo "<pre>".print_r($response,2)."</pre>";

        $response = array();
    }

    return $response;


via Chebli Mohamed

Laravel Increase Upload file Size Heroku

It looks like I cannot upload more than 2mb file with heroku.

I can upload 3mb file on my local but I can't upload the same file after pushing to heroku. (Using storage S3)

I updated the htaccess file and I have added

ini_set('upload_max_filesize', '64M');

to my controller but it doesn't work.

Is there a way we can change the php.ini setting on heroku?



via Chebli Mohamed

Laravel Socialite + Ionic / Angular ( Sign up with Facebook or Google)

My website already has login with Fb or Google function and it's working fine, now I want to connect it to my ionic app. I wrote the code, and in Ionic it's connecting to Fb API successfully but not posting a request to my server (Laravel), there's no change in the DB. Can anyone figure out what is the issue? Here's my code:

Laravel - Api Social Controller:

     public function mobileProviderLogin($provider)
    {
        try{
            $userinfo = Socialite::driver($provider)->user();
        }catch (\Exception $e){
           return response()->json(array("status" => false,  "message" => "Login failed!"));        }

        Log::debug($userinfo->getId());
        $socialProvider = SocialProvider::where('provider_id',$userinfo->getId())->first();
        if(!$socialProvider){

           
                Log::debug('CONTINUE 1.1');
                $user = User::firstOrCreate(
                    ['name'=>$userinfo->getName(), 'display_name' => $userinfo->getName()] //Create With including email
                );
                
                Log::debug('CONTINUE 1.2');
                $user->socialProvider()->create([
                    'provider_id' =>$userinfo->getId(),
                    'provider' => $provider
                ]);
           
        }
        else
        {
            Log::debug('CONTINUE 2.1');
            $user=$socialProvider->user;
            Log::debug('CONTINUE 2.2');
        }
        
        if ($user != null)
        {
            Log::debug('CONTINUE 3.1');
            auth()->login($user);
        }
   
return response()->json(array("status" => true,  "message" => "Login success!"));  } 

Ionic - service.ts:

  mobileProviderLogin(res: any) {

    return this.http.post(this.env.API_URL + 'auth/mobileProviderLogin', {res:res}
    )
  }

Ionic - Login.ts:

fbLogin() 
 {
  this.fb.login(['public_profile', 'email'])
    .then(res => {
      if (res.status === 'connected') {
        this.isLoggedIn = true;
        this.getUserDetail(res.authResponse.userID);
        this.authService.mobileProviderLogin(res);
        this.route.navigate(['/home']); 
      } else {
        this.isLoggedIn = false;
      }
    }),  (error: any) => {
      console.log(error);
         }
}


via Chebli Mohamed

Is there a way to take the number between two dates and subtract with it in Laravel

So I've been trying to find a way to get/take the number in between two dates in fields "from" and "to"(leave table) then take that number(ex. it's 7) and subtract it with another number from the user table a from a field called leaveBalance it has a default number of 20 so I want that ( 20 -7) and the result to be saved in that specific user who requested the leave, in that leaveBalance field after that is changed, also would it be possible to add an if statement to check if the number between dates is bigger than the number allowed that we have on the leaveBalance to just return an error message

This is the leave table

  1. id
  2. user_id
  3. from
  4. to
  5. type
  6. description
  7. status
  8. message

The user table has the leaveBalance field and the two tables don't have a foreign key relation the user_id on the leave only stores the id of that authenticated user when a leave is created and then it only displays the leaves of that id created on the user's view

This is the Leave Controller

public function create()
     {
        $leaves = Leave::latest()->where('user_id',auth()->user()->id)->paginate(5);
        return view('leave.create',compact('leaves'));
    }
public function store(Request $request)
    {
        $this->validate($request,[
            'from'=>'required',
            'to'=>'required',
            'description'=>'required', 
            'type'=>'required'
            ]);
            $data=$request->all();
            $data['user_id']=auth()->user()->id;
            $data['message']='';
            $data['status']=0;
            $leave =Leave::create($data);
            
            $admins = Admin::all();
            $users = User::where('role_id', 2)->get();

            foreach ($admins as $admins) {
                foreach($users as $users){
                $admins->notify(new LeaveSent($leave));
                $users->notify((new LeaveSent($leave)));
            }
        }
        return redirect()->back()->with('message','Leave Created');

    }

This is the Leave Model:

{
    use Notifiable;

    protected $guarded=[];
    
    public function user(){
        return $this->belongsTo(User::class,'user_id','id');   
     }
}

This is the view of the Leave

<div class="card-body">
                    <form method="POST" action="">
                        @csrf

                        <div class="form-group">
                            <label>From Date</label>
                            <div class="col-md-6">
                                <input class="datepicker" type="text" class="form-control @error('from') is-invalid @enderror" name="from" required="">

                                @error('from')
                                    <span class="invalid-feedback" role="alert">
                                        <strong></strong>
                                    </span>
                                @enderror
                            </div>
                        </div>

                        <div class="form-group">
                            <label>To Date</label>
                            <div class="col-md-6">
                                <input class="datepicker1" type="text" class="form-control @error('to') is-invalid @enderror" name="to" required="">

I'm open to using carbon in this I don't really know much on carbon but I am aware that it's used for dates and such but since I use date picker is that possible?



via Chebli Mohamed

Unable to encrypt uploaded file on S3 using FileVault in Laravel 5.8?

I am using Laravel 5.8.

I am uploading a file on s3 which is successfully uploaded. But I am unable to encrypt using FileVault api.

enter image description here

Below are my configurations:

'kyc-documents' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
            'root' => 'app/kyc',
        ],

My controller code

$file_url = Storage::disk('kyc-documents')->putFileAs('/'.Auth::user()->id,$file,$filename);

            Log::info($file_url); // here it logs as 4/hitbtc_api_key.png


            FileVault::disk('kyc-documents')->encrypt($file_url); // Here it gives error as mentioned below

The error I am getting is as follows

fopen(app/kyc/4/hitbtc_api_key.png.enc): failed to open stream: No such file or directory {"userId":4,"exception":"[object] (ErrorException(code: 0): fopen(app/kyc/4/hitbtc_api_key.png.enc): failed to open stream: No such file or directory at /var/www/html/buy_sell/vendor/soarecostin/file-vault/src/FileEncrypter.php:170)

PS: While I am using local disk it is uploaded with .enc file extension which is correct way it should be. Only issue using s3 configurations in my fileSystem disk.

Please do help



via Chebli Mohamed