How to write to a database with a click in Laravel?

Database operations are very easy to handle in Laravel. Modals, database migrations, and tables make the process pretty straightforward and easy. Let’s go through this tutorial to learn an even more simple way to write to a database with a click in Laravel.

The Sign Up method in Laravel can write your database credentials in a single tap. Consider the few simple steps as shown below to do this.

Create a new signup route

You can first create a new route for signup as shown below.

Route::post('/signup', [
    'as'   => 'signup',
    'uses' => 'SignUpController@manualSignUp',

Add route to Laravel Blade

Next, add the newly created signup route to your Laravel Blade or View file as shown below. Add the route to your form action, so a single tap on the submit button calls the route, and sends your credentials to database using the controller function defined below.

<form action="{{ route('signup') }}" method="post">
    <button type="submit"> submit </button>

Writing into the database with one click laravel

Controller Method

The Controller method defined below adds the user credentials data to the database in a single click.

public function manualSignUp()
   DB::table("users") -> insertGetId(array("firstname" => "Harry", "lastname"=> "Dickson", 
   "passwordHash" => "pass1234", "userslevelID" => 7));

   DB::table("userlevel") -> insertGetID(array("userlevelID" => 
   $userlevelID, "name" => $name));
   return view("pages.manualsignup");

You can call the users table, using the DB facade, and pass in a user’s firstname, lastname, user_id, and password hash, required for signup. Then call the userlevel database table and insert the user’s ID and name to it.