laravel ক্যোয়ারীর জন্য প্রসঙ্গ অনুসারে বাছাই করা পোস্ট দেখানো হচ্ছে৷ তারিখ অনুসারে বাছাই করুন সব পোস্ট দেখান
laravel ক্যোয়ারীর জন্য প্রসঙ্গ অনুসারে বাছাই করা পোস্ট দেখানো হচ্ছে৷ তারিখ অনুসারে বাছাই করুন সব পোস্ট দেখান

how to create laravel Project and run without artisan

how-to-create-laravel-and -run-without-artisan
Create Laravel Application and Run without artisan command
In this post, I will going to explain about how to Create Laravel project and run laravel project without “php artisan serve” command. At first, create a laravel project. After installing a laravel project you have to use “php artisan serve” command in cmd to access the created project. Every time to access your project you have to run this command. It's boring. That's why today, i will going to share a trice of laravel how to run without “php artisan serve” command as like php project (Ex: localhost/your_folder_name).

Two simple steps to run laravel without artisan Command:

.htaccess File:

In public folder, you will see ".htaccess" file. Just Copy this ".htaccess" file from public directory and paste on root of your project directory.

Rename File:

I hope you completed the first step. Now, find the "server.php" file in root of your project directory. Then, just rename to "index.php".

Your job is done. Now, in your browser, just type localhost/your_folder_name and hit Enter key.

By following two simple steps, your Laravel project will run without Php Artisan Serve Command.

If anyone wants to make the application public, the more easy and fastest way is:



  • Rename the "server.php" file in root directory with "index.php".
  • Move your .htaccess from public folder to root directory.
  • Make your directory accessible to Apache2. 

Set correct file/folder permissions:

If you set any of your files/folders with 777 permissions, It's mean you are allowing Anyone to read, write and execute that file/folder in that directory. You have given Anyone (any hacker or malicious person in the entire world) permission to upload Any file/folder, virus or any other file, and Then execute that file.

If you set your files/folder permission to 777 that means you have opened your server to anyone.

Create Laravel Project:

There are few steps to create laravel project. In below, I am going to describe all steps.

Laravel Download and Install Via Composer: 

Laravel framework uses Composer for installation and dependency management. To get Composer visit composer.org . 

Now you can install Laravel by the following command from your terminal:
composer create-project laravel/laravel project_name 

By using the above command, you will be able to download and install a fresh copy of Laravel in a new project_name folder within your current directory.

Alternatively you can also download a  fresh copy of the Laravel repository from GitHub manually. Then you have to run the composer install command in the root of your manually created project directory. This command is responsible to download and install the framework's dependencies.

Apply Permissions After Installing Laravel Project:

After installing Laravel Project, you need to grant the web server write permissions in the app/storage directories.

Need to Serve Laravel after Install Project:

You have to use a web server such as Apache to serve Laravel applications. You can use the serve Artisan command. that is 

php artisan serve

By default the web server is used port 8000. If that port is already in use, you have to specify what port to use. To add another port just add the --port argument:

php artisan serve --port=8080

Directory Structure of Laravel Application:

After installing the Laravel Application, take a look around the laravel application to know about the the directory structure. 

The app directory contains many folders such as Http, Models, Console, Providers and Exceptions. Here, the Http folder contain Controllers and Middleware folders. 

In Controllers folder, all controller pages of the project are located.

In Models folder, all model pages of the project are located. 

database folder contain migrations folder. In migrations folder you can see two migration files named "create_users_table.php" and "create_password_resets_table".

Open "create_users_table.php" file then you can see two different function named "public function up()" an "public function down()". You can create any table using "public function up()" function and using "public function down()" function you can drop any table.

public folder contains css, javascript, bootstrap and image files.

resources folders contains many folders such as js, lang and views. In views folder, all blade pages are located.

routes folder contain web.php page that is responsible to write all route of your laravel project.

In .env file, you can set up database name, user name and user password. That you have created for your project.

Most of your application's code will reside somewhere in this directory. You may also wish to explore the app/config directory and the configuration options that are available to you.

Creating A Migration in your project:

In database folder, there is a file named "create_users_table.php" under migrations folder. In this file by default there is a table Schema "users". Now you can create users table in your database by running migration command.

php artisan migrate

Once the above command is used then your migration table "users" will be created in your database that you have connected in .env file.

You can also create table in database manually. For that you have to put two field in every table. That is created_at and updated_at.

Set Default value current_timestamp for created_at and default value null for updated_at.

In simple php application, you have to create database table manually. But in laravel you can database table with migration command or manually created database table. 

Insert value in database using Laravel:

If everything going fine, now it's time to insert some value in database table using laravel model and controller. For that, you have to create a form design. Assume your form design is ready. Now you have to insert form value in database table. That's why you need to code under store function in controller page. Assume you have written insert code in controller page under store function and you data successfully inserted into associated database table.

Displaying data from your database table:

After inserting data into database table you need to display in web page. That's why you need to code under index function in your controller page.

Actually you have to pass your data view page through controller page. In your view page you need to show your data. your can use php loop to display data. 

By following the above article i hope anyone can easily create laravel application and also able to run laravel Application without artisan command.
Read More

3 Steps to learn Laravel Easily | Laravel Crud Operation with Authentication

 Laravel is a strong MVC PHP framework, designed for developers who need a simple and elegant toolkit to bring full- featured web operations. Laravel was created by Taylor Otwell.


This article will guide the developers who want to learn easily Laravel through some simple steps.

3 Steps to learn Laravel Easily:
Step 1: Download laravel and Authentication Screen Setup
Run the following command to download Laravel Latest Vesrion - 
  • composer create-project laravel/laravel project-laravel
Atfer running the above command laravel project will be Downloaded in htdocs folder (Xampp)/ www folder (Wamp). then go in your project folder and run the following two command one by one to setup laravel default Authentication - 
  • composer require laravel/ui
  • php artisan ui vue –auth
    Install Laravel Form Collective:
  •     composer require laravelcollective/html
Step 2: Connect Laravel Project to Database
In this tutorial I am going to use MySQL. So, at first I am going to create a Database "project_laravel". Then create two table name "users" and "subject" in this database.
Now go to your project folder and find .env file (located in your project root folder) and just open this file.


Replace the database name with your database name and user name keep as "root". That's it. Your are now successfully connected your project to MySql server.


Step 3: Create View, Model & Controller File.
  • Create Route in the web.php file
Route::resource('crud', 'App\Http\Controllers\SubjectController');
  • Create View File
go to project folder and create a blade file in resources>views. Suppose this blade file name "crud.blade.php". Data will be appends in this file.

Content of view file:
  • Create Model file
go to project folder and create a model file in app>Models. Suppose this Model file name "Subject.php". Subject related table entity and attribute will be defined here. model for users table will be automatically created while project downloaded. following command will generate the model file.
php artisan make:model Models\Subject

Content of Model file:



  • Create Controller file
go to project folder and create a model file in app>Http>Controllers. Suppose this Controller file name "SubjectController.php". crud related table entity and attribute will be defined here. Following command will generate the controller file.
php artisan make:controller SubjectController --resource

Content of Controller file:



Read More

Laravel - Login with username, email or phone with Status

 



Let's begin with the way to login with username or e mail in laravel 8/7/6 auth. i'm able to come up with easy answer of laravel 7/6 login with username or e mail in authentication. it is smooth to make auth login with username and e mail deal with in laravel 8/7/6 application.

Sometime, we want to create login web page with username or e mail deal with to login. it is super characteristic when you have on your internet site due to the fact it is virtually smooth to bear in mind every person for your purchaser. purchaser if forgot e mail then he has one username. So it is virtually helps.

In laravel 6, i'm able to deliver how you may setup for login with username or e mail step through step. so let's comply with bellow steps.

Step 1: Install Laravel 6

Initially we want to get clean Laravel 6 model utility the use of bellow command, So open your terminal OR command spark off and run bellow command:

composer create-project laravel/laravel example-app

Step 2: Install Laravel UI

You should observe few step to make auth for your laravel 6 utility.

At last go into project folder and open terminal then type and run the following command for running the project.

 php artisan serve

Then Create a Table named 'users'. 

3.create database and tbl users. insert user data

4.config .env file.

5. then run 

composer require laravel/ui

php artisan ui vue --auth

php artisan migrate



6. now project is ready.


7. install laravel collective.

composer require laravelcollective/html


Step 3: Generate Auth Scaffold


Here, we want to generate auth scaffolding in laravel 6 the use of laravel ui command. so, let's generate it via way of means of bellow command:


personal home page artisan ui bootstrap --auth

Now you want to run npm command, in any other case you cannot see higher format of login and sign in page.


Install NPM:


npm install


Run NPM:


npm run dev


Step 4: Add Username Column


Now upload new column username on your customers table, so that you can in reality replace your migration as like bellow.


migration


Now you could run migration


personal home page artisan migrate


Step 5: Update Login View


Laravel has created default login blade file. we want to feature comman username subject on it and cast off e mail subject. so let's replace like as bellow:


Just add field "username" and "status" in User Table.

Add these field name in User Model.

Make Change in Login Page "email" to "username" and type="email" to type="text"

then edit LoginController.php

add 

use Illuminate\Http\Request;

then add 

public function username()

    {

        return "username";

    }


    /**

     * Get the needed authorization credentials from the request.

     *

     * @param  \Illuminate\Http\Request  $request

     * @return array

     */

    protected function credentials(Request $request)

    {

        //return $request->only($this->username(), 'password');

        return ['username'=>$request->{$this->username()},'password'=>$request->password,'status'=>'1'];

    }


File should be like this:

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;

use App\Providers\RouteServiceProvider;

use Illuminate\Foundation\Auth\AuthenticatesUsers;

use Illuminate\Http\Request;

class LoginController extends Controller

{

    /*

    |--------------------------------------------------------------------------

    | Login Controller

    |--------------------------------------------------------------------------

    |

    | This controller handles authenticating users for the application and

    | redirecting them to your home screen. The controller uses a trait

    | to conveniently provide its functionality to your applications.

    |

    */


    use AuthenticatesUsers;


    /**

     * Where to redirect users after login.

     *

     * @var string

     */

    protected $redirectTo = RouteServiceProvider::HOME;


    /**

     * Create a new controller instance.

     *

     * @return void

     */

    public function __construct()

    {

        $this->middleware('guest')->except('logout');

    }


    public function username()

    {

        return "username";

    }


    /**

     * Get the needed authorization credentials from the request.

     *

     * @param  \Illuminate\Http\Request  $request

     * @return array

     */

    protected function credentials(Request $request)

    {

        //return $request->only($this->username(), 'password');

        return ['username'=>$request->{$this->username()},'password'=>$request->password,'status'=>'1'];

    }

}

Thats it. 

Read More

How to create laravel auth login system

How to create laravel auth login system

In this article, I'm going to show How to create laravel auth login system. It's so easy to create login using laravel auth login. "php artisan make:auth" command can perform this task. In this article, I am going to create login system using laravel auth login.

I will create laravel auth login system with following steps.

1. Create a laravel project.
2. Create a database named "login".
3. Open ".env" file located root of your project folder.
4. Go to line no 9 and setup your database name, username and password.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=login
DB_USERNAME=root
DB_PASSWORD=

5. Run "php artisan make:auth" command in terminal.

(In laravel 6.0, "php artisan make:auth" command is not defined. For fresh laravel 6.0 project, Install the laravel/ui Composer package and run php artisan ui vue --auth in a fresh Laravel application.
Example: run first, "composer require laravel/ui "^1.0" --dev" then run "php artisan ui vue --auth" the you will show "authentication scaffolding generated successfully").

Then you will see authentication scaffolding generated successfully.

6. Open "database" folder located root of project folder.

7. Open "migrations" folder located on "database" folder.

your table Schema is here line number 14.

 public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

8. Run "php artisan migrate" command.

"users" table will be created in "login" database.

9. Your job is done. Now, go your browser and click register then fill up all fields and complete your registration.

10. After completing registration, Just login your system. If everything fine then you will be reached in dashboard "home.blade.php". That's all, your login system is created successfully using laravel auth login.

11. login/registration page is located in "resources/views/auth/" folder. You can customize as your wise.

resources/views/auth/(register.blade.php or login.blade.php)

By following the above all steps you can easily create laravel login system using laravel auth login.
Read More

Laravel 6.0 CRUD Operation using Bootstrap Part 4 ( Delete Data From DB )

In this Post, i'm going discuss about how to Update a record or data in MySQL database using laravel. For Updating record or data in MySQL database using laravel at first you have to create a table in data base.
After create a table in the MySQL database you need to insert record or data on it. If you want to know how to insert data in laravel please visit the link : Insert Data in Laravel
Then after insert data into database you have to view data from database. If you want to know how to insert data in laravel please visit the link : View Data From Database in Laravel
After insert and view data if need to update record or data. If you want to know how to insert data in laravel please visit the link : Update Data in Database using Laravel
After that insert, view and update data if need to delete record or data.
All the steps for deleting data in database i have shown in my project. You can follow the project to delete data from database using Laravel.

Read More

How to Get the Last Inserted Id Using Laravel 6.0

Four Simple Ways to get last Inserted Id in Laravel 6.0

Here in this article, I'm going to share with you how to get last inserted ID in laravel with 4 simple method. 
You want to get last inserted ID in laravel application. In following i have discussed about 4 different way to get last inserted ID in laravel. You can use any of the following way to get last ID of inserted record in laravel application.

If you have experience with PHP and Laravel then you almost know the require to get last inserted Id. So, You need to get last insert Id then you can use save(), create() and insertGetId() method in laravel application. In this post, i am going to describe Four way to get last inserted Id in laravel application.

So, in this post i am going to show you four example for getting last insert Id in Laravel Application:
Those are -
  1. insertGetId() method
  2. lastInsertId() method
  3. create() method and
  4. save() method.
Now, I am going to describe the above four method one by one.
  • insertGetId() method - There is the following code sample
public function getLastInsertedId() { 
 $a = ['name' => 'Amit Sarker', 'email'=>'antu123@gmail.com']; 
 $b = User::create($a); 
 return $b->id; 
}
  • lastInsertId() method - There is the following code sample
public function getLastInsertedId() { 
 DB::getPdo()->lastInsertId(); 
}
  • create() method - There is the following code sample
public function getLastInsertedId() {
 $id = DB::table('users_table') 
 ->insertGetId( 
  ['name' => 'Amit Sarker', 'email'=>'antu123@gmail.com'] 
 ); 
return $id; 
}
  • save() method - There is the following code sample
public function getLastInsertedId(){ 
 $user_data =new User(); 
 $user_data->name = "Amit Sarker"; 
 $user_data->email = "antu123@gmail.com"; 
 $user_data->save(); 
 return $user->id; 
}
Here, In this video, I'm going to apply one method. You can follow my video to get last inserted Id.
Thank you.

Read More

Laravel 6.0 CRUD Operation using Bootstrap Part 3 ( Upadte Data in DB )

In this Post, i'm going discuss about how to Update a record or data in MySQL database using laravel. For Updating record or data in MySQL database using laravel at first you have to create a table in data base.
After create a table in the MySQL database you need to insert record or data on it. If you want to know how to insert data in laravel please visit the link : Insert Data in Laravel
 Then after insert data into database you have to view data from database. If you want to know how to insert data in laravel please visit the link : View Data From Database in Laravel
After insert and view data if need to update record or data.
All the steps for Updating data in database i have shown in my project. You can follow the project to update data from database using Laravel.

Read More

What is Laravel?

Laravel is a strong MVC PHP framework, designed for developers who need a simple and elegant toolkit to bring full- featured web operations. Laravel was created by Taylor Otwell.

This article will guide the developers who want to learn how to develop a system using Laravel. This tutorial is particularly meant for all those developers who have no previous experience of using Laravel.

Prerequisites:

Before you start with Laravel, we consider that you are so much familiar with HTML, Core PHP, and Advance PHP. However, we suggest you to pick tutorials grounded on these concepts first, to gain a better understanding of Laravel, If you are new to any of these concepts.
Read More

Invoice System Calculation Using Jquery in Laravel

What is Invoice?
Invoice is a list of products that sent or services provided, with a statement of the sum due for these. In other word, It is also called a bill.

An invoice is related to a sale with indicating the products with quantities, prices of products. In one word, an invoice is a business document.

Why need Invoice?
Generally, Payment terms are included on the invoice. Which may indicate the buyer has a maximum number of days in which to pay and is sometimes offered a discount if paid before the due date.

The buyer already paid for the products or services listed on the invoice. For avoiding confusion from buyer to seller, some sellers clearly state in large and/or capital letters on an invoice whether it has already been paid.

In one word,
  1. An invoice for a seller, an invoice is a sales invoice.
  2. An invoice for a buyer, an invoice is a purchase invoice.
But the term invoice indicates money is owed/owing.

How am i going to create Invoice Application?
Here, i'm going to discuss how to create Invoice or Billing Management Application by using Laravel with Jquery.

For making Simple invoice application i have used not only Laravel and JQuery but also we have use Bootstrap and database MYSQL also.

In this application, i will not create Invoice or Billing for one item but here i will make system that will create multiple dynamic item Invoice. This is simple example with source code and this example any one can use for his project or learning purpose like how to developed Invoice System by using Open Source Laravel and Jquery with Mysql and Bootstrap.

From this article, you can gain knowledge to make Simple Billing System in Laravel.

Used Technologies:
  • Mysql
  • Laravel
  • JQuery
  • Bootstrap
Our Created Invoice management system demo will be like the following Demo. In this system, we can add multiple Medicine with Quantity, Unit Price and Total Price.

If you want to add more medicine with different quantity and Unit price and total price then finally you will get the Sub Total Result in "Sub Total" field. Then you can add the vat percentage. Including product Sub total and vat percentage result will be show in the another specific field named "vat+sub total" after that you can paid the amount if any due remaining then the due will be shown in "Due" field and finally you will see the "Grand Total" result in the related field.

Application Demo :

Invoice System Calculation Using Jquery in Laravel

Project Source Code:
<!-- make dynamic input field --> 
<div class="col-md-12"> 
<table class="table table-responsive"> 
<thead> 
<tr> 
<th>Info.</th> 
<th>Medicine Name</th> 
<th>Quantity</th> 
<th>Unit/Price</th> 
<th>Total</th> 
<th>Action</th> 
</tr> 
</thead>
<tbody class="row_container"> 
<tr id="div_{{$row_num}}"> 
<td> 
<a href="javascript:0" class="btn btn-warning"><i class="fa fa-info-circle"></i></a> 
</td> 
<td> 
<input type="text" name="medicine_name" class="form-control" placeholder="Medicine Name"> 
</td> 
<td> 
<input type="text" name="quantity" class="form-control" placeholder="Quantity" id="quantity"> 
</td> 
<td> 
<input type="text" name="unit_price" class="form-control" placeholder="Unit Price" id="unitprice"> 
</td> 
<td> 
<input type="text" name="total" class="form-control" placeholder="Total" id="total" style="cursor: pointer;" readonly> 
</td> 
<td> 
<a href="javascript:0" class="btn btn-danger"><i class="fa fa-minus" onclick="$('#div_{{$row_num}}').remove();"></i></a> 
</td> 
</tr> 
</tbody>
<tbody> 
<tr> 
<td colspan="3"></td> 
<td></td> 
<td></td> 
<td> 
<a href="javascript:0" class="btn btn-success" onclick="addrow();"><i class="fa fa-plus"></i></a> 
</td> 
</tr> 
<tr> 
<td colspan="3"></td> 
<td> <strong>Sub Total:</strong> </td> 
<td> 
<input type="text" name="subtotal" class="form-control" id="subtotal" value="0.00" readonly> 
</td> 
<td></td> 
</tr> 
<tr> 
<td colspan="3"></td> 
<td> <strong>VAT(%):</strong> </td> 
<td> 
<input type="text" name="" class="form-control" id="vat"> 
</td> 
<td></td> 
</tr>
<tr> 
<td colspan="3"></td> 
<td> <strong>VAT+Sub Total:</strong> </td> 
<td> 
<input type="text" name="" class="form-control" id="vatsubtotal" value="0.00" readonly> 
</td> 
<td></td> 
</tr> 
<tr> 
<td colspan="3"></td> 
<td> <strong>Paid:</strong> </td> 
<td> 
<input type="text" name="" class="form-control" id="paid"> 
</td> 
<td></td> 
</tr> 
<tr> 
<td colspan="3"></td> 
<td> <strong>Due:</strong> </td> 
<td> 
<input type="text" name="" class="form-control" id="due" value="0.00" readonly> 
</td> 
<td></td> 
</tr>
<tr> 
<td colspan="3"></td> 
<td> <strong>Grand Total:</strong> </td> 
<td> 
<input type="text" name="" class="form-control" id="grandtotal" value="0.00" readonly> 
</td> 
<td></td> 
</tr> 
</tbody> 
</table> 
</div>

<script type="text/javascript"> 
$(document).ready(function() { 
$("#total").click(function() { 
/*var quantity = document.getElementById("quantity").value;*/ 
var quantity = $("#quantity").val(); 
var unitprice = $("#unitprice").val(); 
var total = (quantity*unitprice); 
$('#total').val(total); 
$('#subtotal').val(total); 
});

$('#vat').change(function() { 
var vInput = this.value; 
var subtotal = $("#subtotal").val(); 
var vInput = ((vInput*subtotal)/100); 
var vstotal = (parseFloat(subtotal)+parseFloat(vInput)).toFixed(1); $('#vatsubtotal').val(vstotal); 
});

$('#paid').change(function() { 
var pInput = this.value; 
var vatsubtotal = $("#vatsubtotal").val(); 
if((pInput < vatsubtotal) || (pInput <= vatsubtotal)){ $('#paid').val(pInput); 
var dInput = (vatsubtotal-pInput); 
$('#due').val(dInput); 
var total = $("#total").val(); 
var subtotal = $("#subtotal").val(); 
var gtInput = (parseFloat(total)+parseFloat(subtotal)+parseFloat(vatsubtotal)).toFixed(1); $('#grandtotal').val(gtInput); 
}else{ 
alert('You are paying so much amount'); 
});
});
</script>
In the following video, I'm showing all the steps. Please follow the all steps to create Invoice System Calculation Using Jquery, Laravel, Bootstrap and MYSQL.

Read More

CRUD Operations in Laravel 6 Tutorial with Example ( View Data From DB )

In this Post, i'm going discuss about how to retrieve/view a record or data from MySQL database using laravel.
For retrieve/view record or data from MySQL database using laravel at first you have to create a table in data base. After create a table in the MySQL database you need to insert record or data on it.
If you want to know how to insert data in laravel please visit the link : Insert Data in Laravel

All the steps for retrieving or view data from database i have shown in my project. You can follow the project to view data from database using Laravel.
Read More

Laravel 6.0 CRUD Operation using Bootstrap Part 1 ( Save Data in DB )

In this video, I'm going to show you how to insert data in database using laravel framework PHP. For insert data in MySQL using laravel first we have to create a table in data base.
Table Design:




Laravel Model Code:

Laravel Controller Code:

Project Demo:


Here, all the steps for inserting data into database in the Project. Just follow steps by steps.


Read More

Store Form data to mysql as JSON in Laravel 6.0

Store Form data to mysql as JSON in Laravel 6.0

Sometime, In laravel projects we need to store data in database into json format. In this simple laravel 6 store json data example, we will store form data to json format in database step by step from scratch.
Just follow few steps and simply store your data to database into json format laravel based project.
Read More

Add Remove Input Fields Dynamically using Javascript & Html

What is Javascript Dynamic fields?
When the input field will not be static and we can change the number of input field by clicking the button then it is called the dynamic fields.

Why use Javascript Dynamic fields?
In our application, sometimes we need to add more details of the products. In that case, we use add more button so that we can easily add the more details about the product.

For example, when we going to add a medicine name "PARACETAMOL" in the system. we have to think about the variation of this product. Because PARACETAMOL has different variation. In that case we need to use dynamic input field option. So that, we can easily add this multiple variation product in the system.

That's the main motive to use javascript dynamic fields in the application.

How looks Javascript Dynamic fields?
In the below, there is a demo of Javascript dynamic fields. It looks exactly like the following. 
In this demo, i have used two button. 
  1. Minus Mark Button
  2. Plus Mark Button
Once you click on "Plus Mark Button" then one input field row will be automatically added in the system.

But if you click on "Minus Mark Button" then one input field row will be automatically Removed from the system.

Preview Example:

Dynamically input field using javascript

Way to create dynamic Add/Remove input field?
Today, I'm going to show How to create add/remove input fields dynamically with JavaScript in laravel 5.8 project.

We can easily create Add more fields and Remove group of input fields using JavaScript in laravel. We will create javascript dynamic fields with bootstrap 4 and JavaScript in laravel project.

Use laravel validation for add more input fields. You can add more multiple input fields like sometimes we need to add same information add multiple time with same form input. That's why we will create table row with input fields and add add more button so when you click on that button then it will append new row with input fields.

There is the Code Source. By using this code you can easily create Dynamic Add/Remove Input Fields. You can also watch the following video. In this video i have shown how to use this code properly.

Source Code:

<!DOCTYPE html> 
<html> 
<title>Page Title</title> 
<body> 
<?php $row_num=1;?> 
<table class="table table-responsive"> 
<thead> 
<tr> 
<th>Info.</th> 
<th>Medicine Name</th> 
<th>Quantity</th> 
<th>Unit/Price</th> 
<th>Total</th> 
<th>Action</th> 
</tr> 
</thead>
<tbody class="row_container"> 
<tr id="div_{{$row_num}}"> 
<td> 
<a href="javascript:0" class="btn btn-warning"><i class="fa fa-info-circle"></i></a> 
</td> 
<td>
<input type="text" name="medicine_name" class="form-control" placeholder="Medicine Name"> 
</td> 
<td> 
<input type="text" name="quantity" class="form-control" placeholder="Quantity"> 
</td>
<td> 
<input type="text" name="unit_price" class="form-control" placeholder="Unit Price"> 
</td> 
<td> 
<input type="text" name="total" class="form-control" placeholder="Total">
</td>
<td> 
<a href="javascript:0" class="btn btn-danger"><i class="fa fa-minus" onclick="$('#div_{{$row_num}}').remove();"></i></a> 
</td> 
</tr> 
</tbody> 
</table> 
</body> 
</html>

<script type="text/javascript"> 
var RowNum = '{{$row_num}}'; 
function addrow(){ 
RowNum++; 
var html = ""; 
html += '<tr id="div_'+RowNum+'">'; 
html +='<td>'; 
html +='<a href="javascript:0" class="btn btn-warning"><i class="fa fa-info-circle"></i></a>';
html +='</td>';
html +='<td>'; 
html +='<input type="text" name="medicine_name" class="form-control" placeholder="Medicine Name">'; 
html +='</td>'; 
html +='<td>';
html +='<input type="text" name="quantity" class="form-control" placeholder="Quantity">'; 
html +='</td>'; 
html +='<td>'; 
html +='<input type="text" name="unit_price" class="form-control" placeholder="Unit Price">'; 
html +='</td>'; 
html +='<td>';
html +='<input type="text" name="total" class="form-control" placeholder="Total">'; 
html +='</td>'; 
html +='<td>'; 
html +='<a href="javascript:0" class="btn btn-danger"><i class="fa fa-minus"  onclick="$(\'#div_'+RowNum+'\').remove();"></i></a>'; 
html +='</td>'; 
html +='</tr>';
$('.row_container').append(html);}
</script>
Here is the video to create dynamic Add/Remove input field in Laravel using JavaScript. Thank you.
Read More