Add Product

In this tutorial, we are going to teach you, how to add product in database.


Step 1 :  Create product table in database.

CREATE TABLE `laravel_project`.`product` ( `id` INT NOT NULL AUTO_INCREMENT , `user_id` VARCHAR(50) NOT NULL , `product_name` VARCHAR(300) NOT NULL , `product_price` VARCHAR(100) NOT NULL , `product_quantity` VARCHAR(100) NOT NULL , `status` ENUM('0','1') NOT NULL , `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , PRIMARY KEY (`id`)) ENGINE = InnoDB;


Step 2 : Open your dashboard page (successlogin.blade.php)  and create add product form in modal popup.

<!-- Open Modal Popup Code Start Here-->
<div id="add_modal_popup" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Add Product</h4>
      <!-- Add Product Form -->
      <form method="post" action="{{url('/add-product')}}">
        <div class="modal-body">
          <label>Product Name : </label>
          <input type="text" class="form-control" name="product_name" required>
          <label>Product Price : </label>
          <input type="text" class="form-control" name="product_price" required>
          <label>Product Quantity : </label>
          <input type="text" class="form-control" name="product_quantity" required>
          <label>Status : </label>
          <select name="status" class="form-control" required>
            <option value="">---Select Status---</option>
            <option value="1">Active</option>
            <option value="0">Inactive</option>
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
          <button class="btn btn-success" type="submit">Save</button>
<!-- Open Modal Popup Code End Here-->


Step 3 : Open your main controller ( MainController.php ) and create add product function so that we can save the product details.

function add_product(Request $request)
	//Get product details
	$values = array(
		'user_id' => Auth::user()->id,  //get user id from session
		'product_name' => $request->input('product_name'),
		'product_price' => $request->input('product_price'),
		'product_quantity' => $request->input('product_quantity'),
		'status' => $request->input('status')

	// Insert prodcut details in product table

	//back to success message 
	return Redirect::back()->with('msg','Product added successfully.');


Step 4 : Now create a route in web.php for add product detail.



Step 5 : Create success message of add product in dashboard page (successlogin.blade.php) .

@if($message = Session::get('msg'))
  <div class="alert alert-success alert-block">
      <button type="button" class="close" data-dismiss="alert">X</button>


Result :

Source Code:

Small Laravel Project

In this project. We are providing you, how to create small project in Laravel....

Source Code