lundi 18 janvier 2021

HTTP 403 - Laravel 5.5 / API / Incoming POST / HTTP Header

I run a LAMP stack, PHP 7, Laravel 5.5.

I have an API route to allow incoming POST request. I am able to get the POST request to work except for from one particular App, where my App would return a 403. I've drilled down to most-likely it is the problem with the HTTP request. Here it is:

A sample HTTP Request form a working incoming POST:

POST /api/v1/webhook HTTP/1.1|Host:app.myapp.com|Accept:/|Accept-Encoding:deflate, gzip|Transfer-Encoding:chunked|Content-Type:application/json|X-MyApp-Token:123456789ABCDEFG|User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36|X-Real-IP:xxx.xxx.xxx.xxx

A sample incoming HTTP Request that gets a 403 from my App:

POST /api/v1/webhook HTTP/1.1|0:Content-Type%3a application/json|1:X-MyApp-Token%3a 123456789ABCDEFG|Accept:application/json, text/plain, /|Content-Type:application/json|User-Agent:axios/0.19.2|Content-Length:1519|Host:app.myapp.com|Connection:close

The 403 one looks a bit strange. (1) what could be the problem? (2) I don't have control of the OTHER server, is it possible for me to fix this on MY APP?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3qsVKtu
via IFTTT

PHP Fatal error: Uncaught ReflectionException: Class App\Exceptions\Handler does not exist

laravel-5.2 migration problem if I enter php artisan migrate command then return this error pls help me... PS D:\xampp\htdocs\newsflash-2021-01-16> php artisan migrate PHP Fatal error: Uncaught ReflectionException: Class App\Exceptions\Handler does not exist in D:\xampp\htdocs\newsflash-2021-01-16\vendor\laravel\framework\src\Illuminate\Container\Container.php:734 Stack trace: #0 D:\xampp\htdocs\newsflash-2021-01-16\vendor\laravel\framework\src\Illuminate\Container\Container.php(734): ReflectionClass->__construct('App\Exceptions\...') #1 D:\xampp\htdocs\newsflash-2021-01-16\vendor\laravel\framework\src\Illuminate\Container\Container.php(629): Illuminate\Container\Container->build('App\Exceptions\...', Array) #2 D:\xampp\htdocs\newsflash-2021-01-16\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(697): Illuminate\Container\Container->make('App\Exceptions\...', Array) #3 D:\xampp\htdocs\newsflash-2021-01-16\vendor\laravel\framework\src\Illuminate\Container\Container.php(230): Illuminate\Foundation\Application->make('App\Exceptions\...', Array) #4 D:\xampp\htdocs\newsflash-2021-01-16\vendor\laravel\framework\src\Illuminate\Container\Container.php(731): Illuminate\Cont in D:\xampp\htdocs\newsflash-2021-01-16\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 734 PHP Fatal error: Uncaught ReflectionException: Class App\Exceptions\Handler does not exist in D:\xampp\htdocs\newsflash-2021-01-16\vendor\laravel\framework\src\Illuminate\Container\Container.php:734 Stack trace: #0 D:\xampp\htdocs\newsflash-2021-01-16\vendor\laravel\framework\src\Illuminate\Container\Container.php(734): ReflectionClass->__construct('App\Exceptions\...') #1 D:\xampp\htdocs\newsflash-2021-01-16\vendor\laravel\framework\src\Illuminate\Container\Container.php(629): Illuminate\Container\Container->build('App\Exceptions\...', Array) #2 D:\xampp\htdocs\newsflash-2021-01-16\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(697): Illuminate\Container\Container->make('App\Exceptions\...', Array) #3 D:\xampp\htdocs\newsflash-2021-01-16\vendor\laravel\framework\src\Illuminate\Container\Container.php(230): Illuminate\Foundation\Application->make('App\Exceptions\...', Array) #4 D:\xampp\htdocs\newsflash-2021-01-16\vendor\laravel\framework\src\Illuminate\Container\Container.php(731): Illuminate\Cont in D:\xampp\htdocs\newsflash-2021-01-16\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 734 PS D:\xampp\htdocs\newsflash-2021-01-16>



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2N7to9K
via IFTTT

Server wont serve pages whenever uploading and parsing data Laravel

I have been developing the Biometric Parsing module for my system I have achieved my goal in reading raw data from the biometric unit into the database. My problem is that whenever a user in my system is uploading a raw biometric file the server wont serve any pages or requests while the upload and reading is being processed. I would like to have some pointers and learn some of the principles in handling this process much better

the biometric file that comes from the unit looks like this

  129   2019-06-23 18:13:10 1   0   0   0
   98   2019-06-23 18:51:46 1   0   0   0
  101   2019-06-23 19:07:29 1   1   0   0
  103   2019-06-23 19:07:37 1   1   0   0
   85   2019-06-23 21:14:01 1   1   0   0
  132   2019-06-23 23:48:54 1   1   0   0
  203   2019-06-24 03:45:44 1   0   0   0
  138   2019-06-24 04:10:06 1   0   0   0
  204   2019-06-24 05:12:57 1   0   0   0
  157   2019-06-24 05:58:07 1   0   0   0

the file has more than 1,700+ lines each line is a biometric record

in my Controller have this to evaluate each line and store it in the database a biometric batch is declared in order to keep track of the biometric data being uploaded

public function store(Request $request)
{
    if(Auth::check()){
        $repeatedRecords =0;
        // evaluate if the file is recieved
        set_time_limit(360);
        if($request->hasFile('BiometricDataFile')){
            $biometricDataLogFile = file($request->BiometricDataFile);
            foreach($biometricDataLogFile as $logFile){
                $BiometricDBRecord = new Biometric;
                $biometricRecord = explode("\t", $logFile);
                $BiometricDBRecord->employee_id = $biometricRecord[0];
                $BiometricDBRecord->location = $request->location;
                $BiometricDBRecord->logDate = Carbon::parse($biometricRecord[1]);
                $date = explode(' ', $biometricRecord[1]);
                $BiometricDBRecord->bioDate = $date[0];
                $BiometricDBRecord->bioTime = $date[1];
                $BiometricDBRecord->uploaded_by = Auth::user()->employee_id;
                if(Biometric::where('logDate','=', $biometricRecord[1])->count() <= 0){
                    $BiometricDBRecord->save();
                }else{
                    $repeatedRecords++;
                }
               
            }

            $newBatch = new BiometricBatch();
            //Setting up data for return to view
            $timeNow = Carbon::now('GMT+8')->toDateTimeString();
            $thirtyMinEarlier = Carbon::now('GMT+8')->subHours(12)->toDateTimeString();
            $biometricDataSaved = Biometric::whereBetween('created_at', [$thirtyMinEarlier, $timeNow])->where('uploaded_by', Auth::user()->employee_id)->get();
            $biometricDataSaved->sortBy('logDate');
            $sortedFirst = $biometricDataSaved->first();
            $sortedLast = $biometricDataSaved->last();
            $newBatch->employee_id = Auth::user()->employee->id;
            $newBatch->batch_upload_date = Carbon::now();
            $newBatch->batch_start_date = $sortedFirst->logDate;
            $newBatch->batch_end_date = $sortedLast->logDate;
            $newBatch->isProcessed = false;
            $newBatch->save();
        }else{ //if the file is not recieved
            return "<h1> File not found </h1>";
        }
            $activityLog = new ActivityLog();
            $activityLog->employee_id = Auth::user()->employee_id;
            $activityLog->action = 'Has uploaded biometric data';
            $activityLog->save();
        
        return view('pages.employeeBiometric')->with('savedLogs', $biometricDataSaved, 'duplicates', $repeatedRecords);
    }else{
        return view('errors.401');
    }
       
}

I have a gut feeling that I should probably do this in javascript or ajax but dont know where to start and how to execute.I would like to learn how to implement this better and learn form my mistakes, thank you have a great day.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3ipKzPx
via IFTTT

Failed asserting that 200 is identical to 302. in laravel feature testing

I am running test in laravel . But it is failing test. I am not getting the reason may because of middleware but not sure.

Here is test function

public function test_example()
    {
        $staff = factory(Staff::class)->create();
        $response = $this->actingAs($staff) 
        ->withSession(['foo' => 'bar'])
            ->get('/products');

        $response->assertStatus(200);
    }
}

Here is the output

   PHPUnit\TextUI\Command::main()


  Tests:  1 failed, 2 passed
  Time:   0.98s

PS C:\projects\coldxlogistics> php artisan test
Warning: TTY mode is not supported on Windows platform.

   PASS  Tests\Feature\DashboardTest
  ✓ dashboard loads fine
  ✓ user cannot see dashboard without login

   FAIL  Tests\Feature\ProductTest
  ⨯ example

  ---

  • Tests\Feature\ProductTest > example
  Expected status code 200 but received 302.
  Failed asserting that 200 is identical to 302.

  at C:\projects\coldxlogistics\tests\Feature\ProductTest.php:24
     20▕         $response = $this->actingAs($staff)
     21▕         ->withSession(['foo' => 'bar'])
     22▕             ->get('/products');
     23▕
  ➜  24▕         $response->assertStatus(200);
     25▕     }
     26▕ }
     27▕

  1   C:\projects\coldxlogistics\vendor\phpunit\phpunit\phpunit:61
      PHPUnit\TextUI\Command::main()


  Tests:  1 failed, 2 passed
  Time:   1.00s

There are multiple middlwares working on routes. for Example

auth,login_auth,two_factor_auth

and what is the purpose of withSession() how to use it? i see the documentation but can;t understand what is foo, bar



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/39JkHKq
via IFTTT

Strange problem: in Laravel 5 project in some cases in the url 'index.php' is showing

My client have website build on Laravel 5. It's working fine. My job was to add some features. And it was working fine. But lately strange thing is showing. Sometimes, but not often in the url 'index.php' is showing. Then the website is showing but it's rendering wrong, only html without css and JS. I noticed that when it is showing and I will log into CMS and then logout everything is going back to normal. It's very strange to me and I don't really know why. For example, normal url is look like this: jjk-law.pl/blog, but sometimes it's like this: jjk-law.pl/index.php/blog. I will add my routes code:

Route::get('/administrator', 'SessionsController@index')->name('panel');

Route::get('/administrator/login', 'SessionsController@loginForm')->name('login');

Route::post('/administrator/login', 'SessionsController@login');

Route::get('/administrator/logout', 'SessionsController@logout');

if(env('CMS_INSTALLED') == false) {
    Route::get('/install-cms', 'SiteController@installForm')->name('install');

    Route::post('/install-cms', 'SiteController@installCMS');

    Route::post('/save-env', 'SiteController@saveEnv');
}

Route::get('/', 'SiteController@home')->name('homepage');

Route::get('/index.php', 'SiteController@home');

Route::post('/s', 'SiteController@search');

if(env('CMS_INSTALLED')) {
    $primary_lang_option = Option::where('name', 'primary_lang')->first();

    foreach (Language::where('active', 1)->get() as $lang) {
        App::setLocale($lang->short_name);

        if($primary_lang_option->value != $lang->short_name) {
            Route::get('/'.$lang->short_name.'/'.__('site.register_page'), 'SiteController@registerForm')->name('member_register_'.$lang->short_name);
        } else {
            Route::get('/'.__('site.register_page'), 'SiteController@registerForm')->name('member_register_'.$lang->short_name);
        }
    }

    Route::post('/register', 'SiteController@register');

    foreach (Language::where('active', 1)->get() as $lang) {
        App::setLocale($lang->short_name);

        if($primary_lang_option->value != $lang->short_name) {
            Route::get('/'.$lang->short_name.'/'.__('site.login_page'), 'SiteController@loginForm')->name('member_login_'.$lang->short_name);
        } else {
            Route::get('/'.__('site.login_page'), 'SiteController@loginForm')->name('member_login_'.$lang->short_name);
        }
    }

    Route::post('/login', 'SiteController@login');

    Route::get('/logout', 'SiteController@logout');

    Route::get('/password/reset', 'Auth\ForgotPasswordController@memberResetPasswordForm');

    Route::get('/password/reset/{token}', 'Auth\ResetPasswordController@showMemberResetForm')->name('member.password.reset');

    Route::post('/password/reset/{token}', 'Auth\ResetPasswordController@setNewPassword')->name('member.password.new');
}

Route::post('/send_mail', 'MailerController@send')->name('send_mail');
Route::get('/wiadomosc-wyslana', 'MailerController@success')->name('form-success');

Route::get('/{path}', 'SiteController@showByUrl')->where('path', '.+');

I think that this problem is somehow connected to CMS, have relation with login and logout to CMS, but exactly how I don't know don't know. Anyone have the same problem? Any advice how to fix it? Thanks



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3nOKHZW
via IFTTT

dimanche 17 janvier 2021

How to use Tag to show children View on top of parent in Laravel blade?

I am new to Laravel and I have been trying to display partial children view on top of parent view using hyperlink. But nothing happens when I click on my hyperlink. on the other hand it is working on normal button.

Here is the code that works without any problem on normal button.

  <button type="button" id="close_register" title="" class='button-custom' data-container=".close_register_modal" 
      data-href="">
        <!-- <strong><i class="fa fa-window-close fa-lg"></i></strong> -->
  </button>

And here is the hyperlink based button code.

<a id="close_register" data-container=".close_register_modal" 
data-href="" class='glowBtn'>Day Close
</a>

Any help would be highly appreciated Thanks in advance.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3ijpPJg
via IFTTT

samedi 16 janvier 2021

Show Products From specific category in Laravel

I just want to show product with "Rumored" table can someone help how can I show them in my side bar? below is my sidebar code. And side bar Already show 12 Latest Products from all categories it must show only 8 product and with "Rumored" category. not from all categories.

<div class="heading mb-2">
    <h3>Rumored Phones</h3>
</div>

<div class="row">
    @foreach ($popular_devices as $device)
    <div class="col-xl-3 col-lg-4 col-md-6 col-sm-6 col-6">
        <div class="device-box">
            @if($device->image)
            <a title=" " href="">
                <img src="" alt="" class="img-fluid"></a>
            @endif
            <a class="title" title="" href=""></a>
        </div>
    </div>
    @endforeach
</div>

<div class="text-center mb-4">
    <a class="btn btn-light btn-block" href="" title="All devices">View All  Devices</a>
</div>

enter image description here



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/38OO3HZ
via IFTTT