Jump to content

The 8 Biggest Laravel Development Mistakes You Can Easily Avoid


Addison Ron

Recommended Posts

What is Laravel?

 

Laravel is one of the a free highly known , open-source PHP web framework , introduced by Taylor Otwell in 2011 as an effort to provide a more advanced alternative to the CodeIgniter framework, which did not provide features such as- built-in support for user authentication and authorization.

 

 

Laravel attempt to take the pain out of development by enabling common tasks used in the mainstream of web projects, such as- authentication, routing, sessions, and caching and become The Best Framework for PHP Development.

 

 

Without any type of sacrificing in application functionality, it makes a pleasing one for the developer. But it is not so easy to work on new technology, there must be some key points which needs to be keep in mind, while working on them.

 

 

Few are the list of some biggest mistakes which is done by the developers during work Laravel framework, but you can avoid them.  Below are the few helpful steps that can be followed in Laravel Development to gain more control over performance.

 

 

8 Biggest Laravel Development Mistakes-

 

1. During installation & setup

2. Application Key

3. Web server Configuration

4. Laravel Nova

5. Database Seeds

6. Remove Development Configuration

7. Backups

8. Migration

 

 

Read the full article and you can easily avoid above mentioned mistakes-

 

1. During Installation & Setup :

 

When you will execute composer install for Laravel 5.6 during installation it will work perfectly but when you want to add any other package or for some other reason if we need to run composer update command then it will not execute. In addition to a server, Composer will be required, which is a streamlined way of dealing with internal and external dependencies. Otherwise you will face the problem –

laravel is not recognized as an internal or external command

 

Solution :

 

During Installation it is most important to know the basic system requirement and compatibility. Laravel installation can be done on most servers, the basic server requirements are:

· PHP >= 7.1.3

· A local PHP environment (i.e.Valet, Homestead, Vagrant, MAMP, etc.).

· A database (You can prefer MySQL also).

v Valet- automatically sets up everything for local PHP environment on Mac and Homestead or any kind of a virtual machine setup for windows. (Selection is based on type of OS, you are using)

v Laravel Homestead is an official, pre-packaged Vagrant box that provides a stable development environment. (No requirement of Webserver Installation or PHP on local machine .

Two ways to installing Laravel framework on a Windows PC- via Composer or via homestead. Choose one of them.

Here We Discussed On Installation Via Composer:

 

Laravel used this PHP dependency manager to manage all its dependencies. To use Laravel without any Hassel, the Composer must be installed on your machine. Make sure your server meets all the mentioned requirements-

ü PHP >= 7.1.3

ü PDO PHP Extension

ü XML PHP Extension

ü Tokenizer PHP Extension

ü Ctype PHP Extension

ü BCMath PHP Extension

ü JSON PHP Extension

ü Mbstring PHP Extension

ü OpenSSL PHP Extension

Once the above requirements become fulfilled , now need to download the Laravel installer using Composer through the command:

composer global require laravel/installer

After that create the fresh Laravel installation in the specified directory via laravel new command.

e.g. Directory named buddy will be created via  laravel new buddy command which is containing a fresh Laravel installation where all dependencies of Laravel are already installed.

 

 

2. Application Key:

 

If the application key is not set, your user sessions and other encrypted data will not be secure.

 

 

Solution:

 

The next thing you should do after installing Laravel is set your application key to a random string. If you installed Laravel via Composer or the Laravel installer, this key has already been set for you by the php artisan key:generate command.

Typically, this string should be 32 characters long. The key can be set in the .env environment file. If you have not renamed the .env.example file to .env, you should do that now. 

 

 

3. Web Server Configuration

 

If the .htaccess file that ships with Laravel does not work with your Apache installation, it sounds that Web server configuration is required.

 

 

Solution:

 

Laravel includes a public/.htaccess file that is used to provide URLs without the index.php front controller in the path. Before serving Laravel with Apache, be sure to enable the mod_rewrite module so the .htaccess file will be honored by the server.

If the .htaccess file that ships with Laravel does not work with your Apache installation, you should try alternative:

 

 

Options + FollowSymLinks -Indexes

RewriteEngine On

RewriteCond %{HTTP:Authorization} .

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^ index.php [L]

Note: If you are using Nginx, the following directive in your site configuration will direct all requests to the index.php front controller:

location / 

{

    try_files $uri $uri/ /index.php?$query_string;

}

When using Homestead or Valet, pretty URLs will be automatically configured.

 

 

4. Laravel Nova:

Your requirements could not be resolved to an installable set of packages. The requested package laravel/nova could not be found in any version, there may be a typo in the package name.

 

 

Solution:

 

Add following options at the end of your composer.json-File

 

"minimum-stability": "dev",

"prefer-stable": true,

and run composer update.

 

 

5. Database seeds

To make staging environment work conveniently, you might take care of so-called “database seeds” – the main data which comes as the first filling the database for the project launch. There will be a chance of something going wrong after when you will move to live server (also called “production”).

Solution:

 

Here are some important points to solve the issue –

 

v Staging server must be as much similar as live server. Same operating system, web-server configuration etc. Then we can minimize the chance of something going wrong after we move to live server (also called “production”).

v Quite an often mistake is for developers to test locally with Windows operating system and Apache web-server (or something like XAMPP), whereas staging/production servers are Linux-based with Nginx server.

 

 

v Another important note is that the client needs to be heavily involved in this testing. By this point you should be performing not only technical testing, but also business logic – something might be missing or overlooked.

 

 

6. Remove Development Configuration

Sometimes a developer might be rushed and forget to remove development variables and configurations, then upload these by accident to the production environment. This can be a disaster for a live application.

 

 

Solution:

 

It’s important for any developer to have a staging environment that mimics the production environment, which houses the live code. Many new developers try to skip the staging environment and go straight from development to production to save time. This is a mistake because staging can help you identify problems that you didn’t catch in development (remember, staging mimics production).

 

 

If you accidentally forget to remove configurations or don’t find bugs until staging, you can still catch them before they hit the production environment.

 

 

7. Don’t forget to run backups

 

Sometimes many developers have poor backup practices, and don’t take back up their data, and in last they again do significant work on project.

 

 

Solution:

 

Sometimes many developers have poor backup practices. Don’t need to back up every hour, but backups should be run each day if you do significant work on a project. Always remember that backups save you hours of recoding, should you lose your data in the event your drive fails

.

If you have a hard time figuring out a problem in your code, back up the system so you will not lose the solution—and hours of work—and must recode it. A backup can also save you from missing a deadline if something happens to go twisted.

 

 

You should also create backups for your clients in the rare case that a client has a critical failure and no backup. It’s a nice gesture, and you can help your client out of a potentially sticky situation.

8. Migration :

 

To save time in short-term, most of the Laravel developers don't use migration features. This is not the correct way to manually create new database tables and directly add new fields in to the database tables.

 

 

Solution:

 

They should use database migration to add or alter anything in the database. Migration is a well-ordered way of specifying table structure without bothering writing a bunch of SQL queries. Even more, migrations work a little like Git as it allows you to make incremental changes, roll back changes, and keep the database structure in sync when multiple teams are working on the same application. It keep all record of how database created and altered over the time, and migrations and seeders make it easier to re-deploy the application, or distribute it to other people.

 

Edited by Funce
Advertising
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...