In Laravel, you can validate nested objects requests using the dot notation to access the nested fields. Here's an example of how to validate a nested object request:

Let's say we have a request that contains an array of user information, each user has a nested object with a name and email field. We want to validate that all users have a name and email field that is required and must be valid email addresses.

First, create a new request class using the artisan command:

php artisan make:request CreateUserRequest

Then, open the CreateUserRequest class and add the following rules method

In the rules method, we're using the * wildcard to specify that these rules apply to all elements in the users array. Then we're using the dot notation to access the nested name and email fields.

Now, in your controller, you can use the new request to validate the incoming request (example at Controller.php)

If the request fails validation, Laravel will automatically redirect back to the previous page with the errors. You can display the errors using the $errors variable in your view.

That's it! You've successfully validated a nested object request in Laravel.

 

 

        
    
  1. First, make sure you have installed Guzzle in your project using a package manager like Composer. If you haven't, you can install it by running the following command in your project directory
  2. Next, create an instance of the GuzzleHttp\Client class, which will be used to send the HTTP request
  3. Define the request options for the POST request, including the URL, request headers, and the JSON payload
  4. Send the POST request using the post() method of the Client instance
  5. Finally, you can retrieve the response data from the $response object
        
    

You can make a database migration with the help of the make:migration Artisan command. Your database/migrations directory is where the new migration will be put. Each migration filename has a timestamp that tells Laravel in what order the migrations should be run:

php artisan make:migration create_users_table

Laravel will try to guess the name of the table and whether or not the migration will create a new table based on the name of the migration. If Laravel can figure out the table name from the name of the migration, the table will already be in the generated migration file. If not, you can just put the table name in the migration file by hand.

If you want to give the generated migration a different path, you can use the —path option when running the make:migration command. The path you give should be relative to the base path of your application.

Run a specific migration file in Laravel.

In some cases you need to run only one migration file in Laravel without affecting or creating other tables. So let's first create a new migration file to create a new table for our application members:

Create the migration file

php artisan make:migrate create_members_table

The command above will create a new file with the name YYYY_MM_DD_HHMMSS_create_members_table.php in database/migrations folder.

Run the migration file

In case you need to run only this specific migration file you can use the --path options in your CLI. The command to run the migration file we just created is the following:

php artisan migrate --path=database/migrations/YYYY_MM_DD_HHMMSS_create_members_table.php

If the command run successfully then a new table called member will be in your database.

 

        
    

Checking which migrations will be executed without running them.

A really handy option for Laravel php artisan migrate command is --pretend. This options forced CLI to show what migrations will be executed without running them. So if you are not sure about your migrations they are going to run then 

        
    

Rollback a specific number of migrations in Laravel

In many cases you want to rollback more than 1 migrations in your Laravel application. Instead of running php artisan migrate:rollback for every migration you want to rollback, you can do it using the --step=n option where n is the number of rollback you want to run.

* Since version 5.3

If you want to rollback all migration you are always free to use the php artisan migrate:reset command

        
    

Create a migration file using the php artisan command to the specified path in Laravel

Laravel comes with some handy CLI tools to manage some major parts in an application. One of which  is the for creating migration files that contain all the necessary commands and fields to create the tables needed by the application to run smoothly. You can use the php artisan make:migration command to create new migration files. It is recommended to use one migration file per database table.

But if you want to create a new migration file with Laravel in a folder other than the default (database/migration) then you can use the option --path at the end of the artisan command.  With the --path option you specify which folder will contain the new migration file. If the path does not exist then the folder will be auto generated.