Categories
javascript

Javascript to automatically scroll down to the bottom of a web page

<script type="application/javascript">
window.scrollTo(0,document.body.scrollHeight);
</script>
Categories
General Laravel

Quick Form creation Laravel

(1) create model.php + migration file + controller

php artisan make:model --migration --controller ContactForm

(2) Define table

public function up()
{
    Schema::create('contact_forms', function (Blueprint $table) {
        $table->id();
        $table->text('name');
        $table->text('email');
        $table->text('subject');
        $table->longText('Message');
        $table->timestamps();
    });
}

(3) create table in Database

php artisan migrate

(4) Define Route

Route::post('/contactform', '[email protected]' );

(5) Create Controller

/**
 * Laravel basic verification of the field email
 */
$this->validate($request, [
    'email' => 'required|email',
]);


/**
 * Create new record in teh database
 */
$contactForm = ContactForm::firstOrCreate([
    'email' => request('email'),
    'name' => request('name'),
    'message' => request('message'),
    'subject' => request('subject'),
]);


if (request()->wantsJson()) {
    Mail::to('[email protected]', request('contactform'))
        ->send(new \App\Mail\ContactForm($request));
    return response('Success Form has been Sent', 201);
}

/**
 * Redirect to the successful page creation
 */
return redirect('/')->with('flash', 'Success You subscribed to our Newsletter ');

(6) Create html email template

php artisan make:mail ContactForm --markdown=emails.contactform
Categories
Laravel

How to resolve storage/oauth-private.key does not exist or is not readable ?

Error when executing

php artisan route:list -c

Error

storage/oauth-private.key does not exist or is not readable

Solution

 php artisan config:clear

php artisan key:generate

php artisan config:clear

Now execute

php artisan route:list -c
Categories
Laravel

Upgrade from Laravel 6 to Laravel 8 ?

#1 – Make sure the composer.json looks like this

"require": {
   "php": "^7.2",
   "fideloper/proxy": "^4.0",
   "laravel/framework": "^8.0",
   "laravel/passport": "^10.0",
   "laravel/socialite": "^5.0",
   "laravel/tinker": "^2.0",
   "laravel/ui": "^3.0",
   "predis/predis": "^1.1"
},
"require-dev": {
   "facade/ignition": "^2.3.6",
   "mockery/mockery": "^1.0",
   "nunomaduro/collision": "^5.0",
   "phpunit/phpunit": "^9"
}

#2 – if you see following issue

laravel/framework replaces illuminate/support and thus cannot coexist with it.

Remove remove illuminate/support

composer remove illuminate/support

#3 – The report, render, shouldReport, and renderForConsole methods of your application’s App\Exceptions\Handler class should accept instances of the Throwable interface instead of Exception instances: Change app/Exceptions/Handler.php as follow

<?php

namespace App\Exceptions;

use Throwable;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
   /**
    * A list of the exception types that are not reported.
    *
    * @var array
    */
   protected $dontReport = [
       //
   ];

   /**
    * A list of the inputs that are never flashed for validation exceptions.
    *
    * @var array
    */
   protected $dontFlash = [
       'password',
       'password_confirmation',
   ];

   /**
    * Report or log an exception.
    *
    * @param  \Throwable  $exception
    * @return void
    */
   public function report(Throwable $exception)
   {
       parent::report($exception);
   }

   /**
    * Render an exception into an HTTP response.
    *
    * @param  \Illuminate\Http\Request  $request
    * @param  \Throwable  $exception
    * @return \Illuminate\Http\Response
    */
   public function render($request, Throwable $exception)
   {
       return parent::render($request, $exception);
   }
}

Helper additional issue

php artisan config:clear
php artisan key:generate
php artisan config:clear
Categories
API Web API

RESTFUL API – HTTP CODE 422 – Unprocessable Entity

The HyperText Transfer Protocol (HTTP) 422 Unprocessable Entity response status code indicates that the server understands the content type of the request entity, and the syntax of the request entity is correct, but it was unable to process the contained instructions.

Categories
General

Error: Cannot find module ‘read-pkg-up’

All issues such as

Error: Cannot find module 'interpret'
Error: Cannot find module 'read-pkg-up'
Error: Cannot find module 'lru-cache'

Solution

delete package-lock.json
npm upgrade

Categories
General Satori Architect

How to fix Satori 80004005 error ?

MRE1=92 -2147467259 SaveReport failed to save the file "0429C038" for report 364. (error 80004005)

Make Sure All parameters are passed

satoriTemplateClass  standard-letter
records_count        287 
permit_number        892 
piece_height         8.5 
piece_weight          0
piece_width           0 
piece_thickness       0.0294 
post_office_drop_date  2021-03-24 
presort_class          standard 
post_office_drop_date. 2021-03-24 

postage category

- letter
- flat
- postcard
  

presort class

firstClass 
standard 
nonprofit 
Categories
General

How to Install Serverless on a Mac ?

Install Node server

brew install node

Install serverless

npm install -g serverless

Configure Serverless

serverless config credentials --provider aws -o --key XXXXXXXXXXXXXXXXX --secret XXXXXXXXXXXXXXXXXX

Serverless Login

serverless login

Serverless Deploy

serverless deploy


Categories
Technical

brew Error: Directory not empty @ dir_s_rmdir – /private/tmp/d20210315-27447-1b2auy5

chown davidr:wheel /private/tmp/

fixed my issue

Categories
BEST PHP CODE

Force PHP ERRORS

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);