Laravel folder permissions

After installation of Laravel you will require to configure some folder permissions. Currently till Laravel version 5.2 we require to set the permission of 2 folders.

  1. storage
  2. bootstrap/cache

These both folder need writable permission. Because we write the logs in storage folder and save cache in bootstrap/cache folder. Most of the developers set permission 777 to these folders.

Never ever set permission 777 to the folders until it is required. If you are giving 777 permission you are allowing anyone to Read, Write and Execute the files. If you are giving writable and executable permission then it's big security concern. ...  Read More

Share This:


Dynamic database connection in Laravel 5.5 | Multiple database connection in Laravel 5.5 | MySQL & Redis database connection in Laravel | Change database or schema dynamically in a connection

So many time If we are working on a big application we need to keep out data in multiple databases. This is very easy to manage multiple database connections in Laravel. You also can create your database connection at run time.

Inside your database configuration file you can define multiple database connections. Like in Laravel 'config/database.php' we can define our multiple database connections.

We also can set our database or schema dynamically within a database connection.

I will show you 3 MySQL and 1 Redis database connection as multiple database connection and I also will connect them dynamically. ...  Read More

Share This:


Laravel RESTful API Tutorial | Laravel RESTful API Example | Login, Register, Logout, and CRUD API in Laravel | Laravel RESTful API Development

A Web API is like a web service which works entirely with HTTP. A RESTful API must follow the REST (REpresentational State Transfer) practices, allowing to orientate the design to the resources, provide standard responses based on the different HTTP status codes.

Methods

HTTP methods are mapped to CRUD (create, read, update and delete) actions for a resource. Although you can make slight modifications such as making the PUT method to create or update, the basic patterns are listed as follows.

HTTP GET: Get/List/Retrieve an individual resource or a collection of resources.
HTTP POST: Create a new resource or resources.
HTTP PUT: Update an existing resource or collection of resources.
HTTP PATCH: Update an existing resource or collection of resources with specified parameters like in all users data if you wanted to update the email id only you can use PATCH.
HTTP DELETE: Delete a resource or collection of resources. ...  Read More

Share This:


Laravel 5.5 Seeding Example | Laravel Seeding | Laravel Database: Seeding

Seeding is very useful while you wanted to keep some dummy data without manual interfere with Database. For example when you deploy you application you insert admin credentials into you users table every time you deploy so that admin user can login. You don't need to to insert those credentials manually every time.
Laravel provides feature of seeding and you can manage your dummy database in your seed classes.



You can create seed like below artisan command:

These command will create a new file 'database/seeds/ProductsTableSeeder.php' and 'database/seeds/UsersTableSeeder.php' which will contain a run() method. ...  Read More

Share This:


Laravel Migration Example | Database: Migrations - Laravel | Laravel 5.5 Migration Tutorial | Database Versioning

If we manage our database manually like if you need to add a column, You directly alter the MySQL database table and add the column.
If you need to add a new table into you MySQL database you directly create a new table.
But here is the question, If you are a number of developers and working on same project how will you get to know that who changed what in your database ?
If right now you are working on second or third version of app, How will you know what was your schema when you launched first version of your application? ...  Read More

Share This:


Syntax error or access violation: 1055 isn't in GROUP BY in Laravel | Laravel : Syntax error or access violation: 1055 Error

This error is not because of the Laravel actually. This is MySQL error and which comes if you have ONLY_FULL_GROUP_BY inside the SQL_MODE variable in your DB.

Of course you can handle it at MySQL level by removing ONLY_FULL_GROUP_BY from you SQL_MODE.

But Laravel also provides the functionality to handle this error.

check your config/database.php And check if inside the mysql settings there is one that is like:

If you turn 'strict' to false will resolve you issue like;

 ...  Read More

Share This:


How do I get HTTP Request body content in Laravel | How to return JSON Request body in Response in Laravel | How to add new parameter in HTTP request body in Laravel

So many time we need to return in REST APIs the request body. For example if you send a POST request with some parameters and you wanted you API access token along with the request body parameters which you sent.

Like below example:

Here is the Request body:

And now you wanted to get register and access token in response along with above request body like below:

How can we do this in Laravel????

Here is the answer of this question. You can get the HTTP request body in Laravel by following code:

Now if you wanted to send the request body with along with access token in JSON response in Laravel, You can do it like following example:

So finally function to return the JSON response after registration of the user looks like:

  ...  Read More

Share This:


Customize validation error response in Laravel 5.5 | How to return Custom validation error response in JSON in Laravel 5.5 | How i can return a customized response in a FormRequest class in Laravel 5.5? | How to write validation rules for JSON request in Laravel 5.5

Laravel 5.5.* has made a change which is big deal with Laravel developers now a days and the change is you can't customize your validation error response like you you did in earlier versions. In earlier versions of Laravel we were able to customize or change our validation error response with below function example:

Now in current versions of Laravel 5.5.* you will not be able to customize your validation error response with this function.

You will require to use followings as well:

If you are using FormRequests to validate data and want to return custom JSON on error response in Laravel 5.5.*, You have to you below function.

It will return all the validation error in JSON. ...  Read More

Share This:


Laravel 5 validation example | How to write validation rules in Laravel | Laravel form validation

While developing the web application we need server side form validations. Laravel does this task beautifully. In this article I'm going to explain how we can do our form validations in Laravel.

We don't need to write the form validations in our Controller code like generally people does.

Here is an example of writing form validation rules in Laravel.

For example here is the form:

When you will submit the form it will go to register route like:

It says the register route has routed to 'postRegister' function which is inside the 'RegisterController'. ...  Read More

Share This:


Laravel Call to undefined method Redis::connection()

The Redis class is built-in to Laravel and connection() is there. It can't be missing.  You might have installed php-redis on your system. Redis can be another class into php-redis. So there may conflict between Laravel Redis alias and another Redis class.

Now there are two solutions for solving this problem.

  1. You just need to edit your app config, open app/config/app.php and replace this line:

And then you can get your Redis instance like this:

2. Remove php-redis

To remove the php-redis you need to run the below command:

Now restart your Redis server by following command:

  ...  Read More

Share This: