Laravel Import Template with Error Handling and Try Catch for failures
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
public function import_data(Request $request)
{
$success = true;
try {
DB::beginTransaction();
foreach ($request->array_or_object as $item) {
$record_payload = [
"name" => $item->name,
"surname" => $item->surname,
];
$record_id = $item->id ?? null;
$inserted_record = RecordModel::updateOrCreate(['id' => $record_id], $record_payload);
if (!$inserted_record) {
$success = false;
break; // Stop further processing if any insert fails
}
}
if ($success) {
DB::commit();
return ['status' => true, 'message' => 'Success, Your import has completed with no issues.'];
} else {
DB::rollBack();
return ['status' => false, 'message' => 'Unsuccessful Transaction. Not an exception.'];
}
} catch (\Exception $e) {
DB::rollBack();
$i = count($e->errorInfo) - 1;
return ['status' => false, 'message' => $e->errorInfo[$i]];
}
}
public function import_data(Request $request) { $success = true; try { DB::beginTransaction(); foreach ($request->array_or_object as $item) { $record_payload = [ "name" => $item->name, "surname" => $item->surname, ]; $record_id = $item->id ?? null; $inserted_record = RecordModel::updateOrCreate(['id' => $record_id], $record_payload); if (!$inserted_record) { $success = false; break; // Stop further processing if any insert fails } } if ($success) { DB::commit(); return ['status' => true, 'message' => 'Success, Your import has completed with no issues.']; } else { DB::rollBack(); return ['status' => false, 'message' => 'Unsuccessful Transaction. Not an exception.']; } } catch (\Exception $e) { DB::rollBack(); $i = count($e->errorInfo) - 1; return ['status' => false, 'message' => $e->errorInfo[$i]]; } }
public function import_data(Request $request)
{
    $success = true;

    try {
        DB::beginTransaction();

        foreach ($request->array_or_object as $item) {
            $record_payload = [
                "name" => $item->name,
                "surname" => $item->surname,
            ];

            $record_id = $item->id ?? null;
            $inserted_record = RecordModel::updateOrCreate(['id' => $record_id], $record_payload);

            if (!$inserted_record) {
                $success = false;
                break; // Stop further processing if any insert fails
            }
        }

        if ($success) {
            DB::commit();
            return ['status' => true, 'message' => 'Success, Your import has completed with no issues.'];
        } else {
            DB::rollBack();
            return ['status' => false, 'message' => 'Unsuccessful Transaction. Not an exception.'];
        }
    } catch (\Exception $e) {
        DB::rollBack();
        $i = count($e->errorInfo) - 1;
        return ['status' => false, 'message' => $e->errorInfo[$i]];
    }
}
Laravel Migration Error – SQLSTATE[HY000] [2002] php_network_getaddresses
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql
failed: Temporary failure in name resolution (SQL: select * from
information_schema.tables where table_schema = laravel and
table_name = migrations and table_type = 'BASE TABLE')
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: Temporary failure in name resolution (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql 
failed: Temporary failure in name resolution (SQL: select * from 
information_schema.tables where table_schema = laravel and 
table_name = migrations and table_type = 'BASE TABLE')

The issue has to do with the env variable DB_HOST
You need to change it. To what your localhost is configured for.
It can most likely be one of the following.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
mysql
127.0.0.1
localhost
or alternatively check your docker container name for your mysql DB:
mysql_container_name
mysql 127.0.0.1 localhost or alternatively check your docker container name for your mysql DB: mysql_container_name
mysql
127.0.0.1
localhost

or alternatively check your docker container name for your mysql DB:
mysql_container_name
Divi – Align Gallery images vertically center

Take note of the height restriction!

In this case we set the height for the default size of landscape images layout for the divi gallery element.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/* Gallery Image Alignment */
.et_pb_gallery_image.landscape {
display: flex;
justify-content: center;
align-items: center;
min-height: 226px;
}
/* Gallery Image Alignment */ .et_pb_gallery_image.landscape { display: flex; justify-content: center; align-items: center; min-height: 226px; }
/* Gallery Image Alignment */
.et_pb_gallery_image.landscape {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 226px;
}
Create New Laravel Project & Generate Auth

Create Project

Just use one.
The are multiple as examples.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
composer create-project --prefer-dist laravel/laravel blog "11.*"
composer create-project --prefer-dist laravel/laravel blog "10.*"
composer create-project --prefer-dist laravel/laravel blog "9.*"
composer create-project --prefer-dist laravel/laravel blog "11.*" composer create-project --prefer-dist laravel/laravel blog "10.*" composer create-project --prefer-dist laravel/laravel blog "9.*"
composer create-project --prefer-dist laravel/laravel blog "11.*"

composer create-project --prefer-dist laravel/laravel blog "10.*"

composer create-project --prefer-dist laravel/laravel blog "9.*"

Generate Auth

An alternative instead of running npm run build.
Run npm run dev OR npm run watch

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
// With Boothstrap
composer require laravel/ui --dev
php artisan ui bootstrap --auth
npm install
npm run build
// With VUE
composer require laravel/ui --dev
php artisan ui vue --auth
npm install
npm run build
// With Boothstrap composer require laravel/ui --dev php artisan ui bootstrap --auth npm install npm run build // With VUE composer require laravel/ui --dev php artisan ui vue --auth npm install npm run build
// With Boothstrap
composer require laravel/ui --dev
php artisan ui bootstrap --auth
npm install 
npm run build

// With VUE
composer require laravel/ui --dev
php artisan ui vue --auth
npm install
npm run build 

Uploading your js build to the server

If you using git and working locally and using laravel vite.
Build your project and use the below gitignore. This will push your build to the server.

The below is that if you don’t include certain directories then your build files will not get uploaded and some servers don’t have suffucient resources to run builds online.
So you need to build locally and upload the build via GIT.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/vendor/
npm-debug.log
yarn-error.log
public/hot
public_html/storage
public_html/hot
public/robots.txt
storage/*.key
.env
.htaccess
Homestead.yaml
Homestead.json
/.vagrant
.phpunit.result.cache
/vendor/ npm-debug.log yarn-error.log public/hot public_html/storage public_html/hot public/robots.txt storage/*.key .env .htaccess Homestead.yaml Homestead.json /.vagrant .phpunit.result.cache
/vendor/
npm-debug.log
yarn-error.log
public/hot
public_html/storage
public_html/hot
public/robots.txt
storage/*.key
.env
.htaccess
Homestead.yaml
Homestead.json
/.vagrant
.phpunit.result.cache
Setup Node.js on Shared Hosting Apache Server (Cpanel)

First off you need access to the server terminal. Or SSH acces. If you have that then you can proceed. Else go get your Login permissions or SSH access.

Connect to your server using SSH or Cpanel terminal.

Run the following curl command to download the Node.js source code:bashCopy code


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash 

This will download the nvm (Node Version Manager) installation script and pipe it to the bash shell to run the script.

Once the installation is complete, run the following command to load nvm:bashCopy code


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
source ~/.bashrc
source ~/.bashrc
source ~/.bashrc

This will activate the nvm environment so you can install Node.js and npm.

Run the following command to install the latest version of Node.js


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
nvm install node
nvm install node
nvm install node

This will install the latest stable version of Node.js and npm.

Verify that Node.js and npm are installed correctly by running the following commands

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
node -v
npm -v
node -v npm -v
node -v 
npm -v

These commands should output the versions of Node.js and npm installed on your server

Keep in mind that the above steps may not work on all shared hosting providers, and some providers may not allow you to install additional software on their servers. It’s always a good idea to check with your hosting provider before attempting to install software on a shared hosting server.

Search

Your Favourite Posts

  • Your favorites will be here.

Latest Content

© Garth Baker 2025 All rights reserved.

Pin It on Pinterest

Garth Baker
en
af
sq
am
ar
hy
az
eu
be
bn
bs
bg
ca
ceb
ny
zh-CN
zh-TW
co
hr
cs
da
nl
en
eo
et
tl
fi
fr
fy
gl
ka
de
el
gu
ht
ha
haw
iw
hi
hmn
hu
is
ig
id
ga
it
ja
jw
kn
kk
km
ko
ku
ky
lo
la
lv
lt
lb
mk
mg
ms
ml
mt
mi
mr
mn
my
ne
no
ps
fa
pl
pt
pa
ro
ru
sm
gd
sr
st
sn
sd
si
sk
sl
so
es
su
sw
sv
tg
ta
te
th
tr
uk
ur
uz
vi
cy
xh
yi
yo
zu
Share This