Crud Operation in Laravel

In this tutorial I’m going to learn how to create Crud operation in Laravel. Please follow some easy steps define below.

Step 1 — Installing Laravel 8

Open terminal in xampp/htdocs and paste below code

composer create-project laravel/laravel example-app

Step 2 — Setting up a MySQL Database

👇 Step 2 — Database Configuration

Setup database with your installed laravel 8 project . lets go to .env folder and put database name and connect to database.

👇 Next go to .env folder and put database name

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=crud-operation
DB_USERNAME=root
DB_PASSWORD=

Next run this command

php artisan migrate

Step 3 — Creating a Database Migration

Run this command

php artisan make:migration create_products_table --create=products

Copy below code and simply paste in your products table

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProductsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->text('detail');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('products');
}
}

Step 4 — Adding a Resource Route

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
return view('welcome');
});

Route::resource('products','ProductController');

Step 5 — Adding a Laravel 8 Controller and Model

run this command

php artisan make:controller ProductController --resource --model=Product

Go to your product controller and paste below code

<?php

namespace App\Http\Controllers;

use App\Product;
use Illuminate\Http\Request;

class ProductController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$products = Product::latest()->paginate(5);

return view('products.index',compact('products'))
->with('i', (request()->input('page', 1) - 1) * 5);
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('products.create');
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'detail' => 'required',
]);

Product::create($request->all());

return redirect()->route('products.index')
->with('success','Product created successfully.');
}

/**
* Display the specified resource.
*
* @param \App\Product $product
* @return \Illuminate\Http\Response
*/
public function show(Product $product)
{
return view('products.show',compact('product'));
}

/**
* Show the form for editing the specified resource.
*
* @param \App\Product $product
* @return \Illuminate\Http\Response
*/
public function edit(Product $product)
{
return view('products.edit',compact('product'));
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Product $product
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Product $product)
{
$request->validate([
'name' => 'required',
'detail' => 'required',
]);

$product->update($request->all());

return redirect()->route('products.index')
->with('success','Product updated successfully');
}

/**
* Remove the specified resource from storage.
*
* @param \App\Product $product
* @return \Illuminate\Http\Response
*/
public function destroy(Product $product)
{
$product->delete();

return redirect()->route('products.index')
->with('success','Product deleted successfully');
}
}

Lets Go to Model and paste below code

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
protected $fillable = [
'name', 'detail'
];
}

Step 6 — Adding your Larevl 8 Blade Views

Go to Resource folder and create view file

1) layout.blade.php

2) index.blade.php

3) create.blade.php

4) edit.blade.php

5) show.blade.php

resources/views/products/layout.blade.php

<!DOCTYPE html>
<html>
<head>
<title>Laravel 6 CRUD Application - Laravel Amit</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.css" rel="stylesheet">
</head>
<body>

<div class="container">
@yield('content')
</div>

</body>
</html>

resources/views/products/index.blade.php

@extends('products.layout')

@section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Laravel 6 CRUD Example from By Laravel Amit</h2>
</div>
<div class="pull-right">
<a class="btn btn-success" href="{{ route('products.create') }}"> Create New Product</a>
</div>
</div>
</div>

@if ($message = Session::get('success'))
<div class="alert alert-success">
<p>{{ $message }}</p>
</div>
@endif

<table class="table table-bordered">
<tr>
<th>No</th>
<th>Name</th>
<th>Details</th>
<th width="280px">Action</th>
</tr>
@foreach ($products as $product)
<tr>
<td>{{ ++$i }}</td>
<td>{{ $product->name }}</td>
<td>{{ $product->detail }}</td>
<td>
<form action="{{ route('products.destroy',$product->id) }}" method="POST">

<a class="btn btn-info" href="{{ route('products.show',$product->id) }}">Show</a>

<a class="btn btn-primary" href="{{ route('products.edit',$product->id) }}">Edit</a>

@csrf
@method('DELETE')

<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</table>

{!! $products->links() !!}

@endsection

👇 resources/views/products/create.blade.php

@extends('products.layout')

@section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Add New Product</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('products.index') }}"> Back</a>
</div>
</div>
</div>

@if ($errors->any())
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif

<form action="{{ route('products.store') }}" method="POST">
@csrf

<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Name:</strong>
<input type="text" name="name" class="form-control" placeholder="Name">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Detail:</strong>
<textarea class="form-control" style="height:150px" name="detail" placeholder="Detail"></textarea>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>

</form>
@endsection

resources/views/products/edit.blade.php

@extends('products.layout')

@section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Edit Product</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('products.index') }}"> Back</a>
</div>
</div>
</div>

@if ($errors->any())
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif

<form action="{{ route('products.update',$product->id) }}" method="POST">
@csrf
@method('PUT')

<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Name:</strong>
<input type="text" name="name" value="{{ $product->name }}" class="form-control" placeholder="Name">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Detail:</strong>
<textarea class="form-control" style="height:150px" name="detail" placeholder="Detail">{{ $product->detail }}</textarea>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>

</form>
@endsection

resources/views/products/show.blade.php

@extends('products.layout')
@section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2> Show Product</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('products.index') }}"> Back</a>
</div>
</div>
</div>

<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Name:</strong>
{{ $product->name }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Details:</strong>
{{ $product->detail }}
</div>
</div>
</div>
@endsection

Lets run php artisan serve

http://localhost:8000/products

I hope its helpful for you.

Tagged : / / /

php version (7.2.34) does not satisfy that requirement.

When i download the Laravel project from Github and setup project i run composer update its showing this types of error

Problem 1
- Root composer.json requires php ^7.3|^8.0 but your php version (7.2.34) does not satisfy that requirement.
Problem 2
- phpro/grumphp[v1.0.0, ..., v1.1.0] require php ^7.3 -> your php version (7.2.34) does not satisfy that requirement.
- phpro/grumphp[v1.2.0, ..., v1.3.1] require php ^7.3 || ^8.0 -> your php version (7.2.34) does not satisfy that requirement.
- Root composer.json requires phpro/grumphp ^1.0 -> satisfiable by phpro/grumphp[v1.0.0, ..., v1.3.1].

Let open editor and run below

composer install --ignore-platform-reqs

Thanks

Tagged : / / /

How to Add Data in DataTable in Laravel Crud

In this tutorial I’m going to describe how to add data in DataTable in laravel 8 we will create single page companies ajax crud application (SPA) using dataTables js, modal and jQuery in laravel 8.

Laravel 8 Ajax CRUD Tutorial using Datatable JS
Step 1 – Download Laravel 8 App
Step 2 – Database Configuration
Step 3 – Installing Yajra Datatables
Step 4 – Make Model & Migration
Step 5 – Make Routes
Step 6 – Create AJAX CRUD Datatables Controller
Step 7 – Create Blade Views File
companies.blade.php
company-action.blade.php
Step 8 – Run Development Server

Step 1 — Download Laravel 8 App

1st step Install laravel project and new setup, lets open the terminal C:\xampp\htdocs and paste below code

composer create-project --prefer-dist laravel/laravel laraveldatatable

Step 2 — Database Configuration

Setup database with your installed laravel 8 project . lets go to .env folder and put database name and connect to database.

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

Next run this command

php artisan migrate

Step 3 — Installing Yajra Datatables

composer require yajra/laravel-datatables-oracle

Then configure datatables package. So go to config directory and open app.php file. And add the following service providers into app.php file:

Go to -> config/app.php and put in providers section

'providers' => [

Yajra\Datatables\DatatablesServiceProvider::class,
],

'aliases' => [

'Datatables' => Yajra\Datatables\Facades\Datatables::class,
]

Then publish laravel datatables vendor package by using below command:

php artisan vendor:publish

Step 4 — Make Model & Migration

php artisan make:model Company -m

Simply copy this code and paste in companies model

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCompaniesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('companies', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->string('name');
$table->string('email');
$table->string('address');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('companies');
}
}

Lets migrate table to database run this command

php artisan migrate

After that, lets go to app/models directory and open company.php model file. Then add the following code into it:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Company extends Model
{

protected $fillable =['name', 'email', 'address'];

}

Step 5 — Make Routes

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
return view('welcome');
});

use App\Http\Controllers\DataTableAjaxCRUDController;

Route::get('ajax-crud-datatable', [DataTableAjaxCRUDController::class, 'index']);
Route::post('store-company', [DataTableAjaxCRUDController::class, 'store']);
Route::post('edit-company', [DataTableAjaxCRUDController::class, 'edit']);
Route::post('delete-company', [DataTableAjaxCRUDController::class, 'destroy']);

Step 6 — Create AJAX CRUD Datatables Controller

php artisan make:controller DataTableAjaxCRUDController -r

Lets go to controller and copy below code and paste there

<?php

namespace App\Http\Controllers;


use Illuminate\Http\Request;
use App\Company;
class DataTableAjaxCRUDController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
if(request()->ajax()) {
return datatables()->of(Company::select('*'))
->addColumn('action', 'company-action')
->rawColumns(['action'])
->addIndexColumn()
->make(true);
}
return view('companies');
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$companyId = $request->id;

$company = Company::updateOrCreate(
[
'id' => $companyId
],
[
'name' => $request->name,
'email' => $request->email,
'address' => $request->address
]);

return Response()->json($company);
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$where = array('id' => $request->id);
$company = Company::where($where)->first();

return Response()->json($company);
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$company = Company::where('id','$request->id')->delete();
return Response()->json($company);
}
}

Step 6 — Create Blade Views File

Create two blade views file, which is following:

  • companies.blade.php

Next go to companies.blade.php file and paste below code

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Laravel 8 AJAX CRUD using DataTable js Tutorial From Scratch - Tutsmake.com</title>
<meta name="csrf-token" content="{{ csrf_token() }}">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" >
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<link href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css" rel="stylesheet">
<script src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
</head>
<body>
<div class="container mt-2">
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Laravel 8 Ajax CRUD DataTables Tutorial</h2>
</div>
<div class="pull-right mb-2">
<a class="btn btn-success" onClick="add()" href="javascript:void(0)"> Create Company</a>
</div>
</div>
</div>
@if ($message = Session::get('success'))
<div class="alert alert-success">
<p>{{ $message }}</p>
</div>
@endif
<div class="card-body">
<table class="table table-bordered" id="ajax-crud-datatable">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Address</th>
<th>Created at</th>
<th>Action</th>
</tr>
</thead>
</table>
</div>
</div>
<!-- boostrap company model -->
<div class="modal fade" id="company-modal" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="CompanyModal"></h4>
</div>
<div class="modal-body">
<form action="javascript:void(0)" id="CompanyForm" name="CompanyForm" class="form-horizontal" method="POST" enctype="multipart/form-data">
<input type="hidden" name="id" id="id">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Company Name</label>
<div class="col-sm-12">
<input type="text" class="form-control" id="name" name="name" placeholder="Enter Company Name" maxlength="50" required="">
</div>
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Company Email</label>
<div class="col-sm-12">
<input type="email" class="form-control" id="email" name="email" placeholder="Enter Company Email" maxlength="50" required="">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Company Address</label>
<div class="col-sm-12">
<input type="text" class="form-control" id="address" name="address" placeholder="Enter Company Address" required="">
</div>
</div>
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary" id="btn-save">Save changes
</button>
</div>
</form>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
<!-- end bootstrap model -->
</body>
<script type="text/javascript">
$(document).ready( function () {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$('#ajax-crud-datatable').DataTable({
processing: true,
serverSide: true,
ajax: "{{ url('ajax-crud-datatable') }}",
columns: [
{ data: 'id', name: 'id' },
{ data: 'name', name: 'name' },
{ data: 'email', name: 'email' },
{ data: 'address', name: 'address' },
{ data: 'created_at', name: 'created_at' },
{data: 'action', name: 'action', orderable: false},
],
order: [[0, 'desc']]
});
});
function add(){
$('#CompanyForm').trigger("reset");
$('#CompanyModal').html("Add Company");
$('#company-modal').modal('show');
$('#id').val('');
}
function editFunc(id){
$.ajax({
type:"POST",
url: "{{ url('edit-company') }}",
data: { id: id },
dataType: 'json',
success: function(res){
$('#CompanyModal').html("Edit Company");
$('#company-modal').modal('show');
$('#id').val(res.id);
$('#name').val(res.name);
$('#address').val(res.address);
$('#email').val(res.email);
}
});
}
function deleteFunc(id){
if (confirm("Delete Record?") == true) {
var id = id;
// ajax
$.ajax({
type:"POST",
url: "{{ url('delete-company') }}",
data: { id: id },
dataType: 'json',
success: function(res){
var oTable = $('#ajax-crud-datatable').dataTable();
oTable.fnDraw(false);
}
});
}
}
$('#CompanyForm').submit(function(e) {
e.preventDefault();
var formData = new FormData(this);
$.ajax({
type:'POST',
url: "{{ url('store-company')}}",
data: formData,
cache:false,
contentType: false,
processData: false,
success: (data) => {
$("#company-modal").modal('hide');
var oTable = $('#ajax-crud-datatable').dataTable();
oTable.fnDraw(false);
$("#btn-save").html('Submit');
$("#btn-save"). attr("disabled", false);
},
error: function(data){
console.log(data);
}
});
});
</script>
</html>

Lets go to your browser and run this url

http://127.0.0.1:8000/ajax-crud-datatable

Now its open like this and successfully working and store in database as well.

Thanks 🙏🙏

Tagged : / / / /

How to Add Facebook Comment in HTML page

In this tutorial I’m going to describe how to add facebook comment in html page, please follow some easy steps its helpful for you.

1st step go to Facebook for Developers Facebook comment

2 nd step: Paste your website URL which website you want to show facebook comment.

Next you’ll get Code 1st code put in after body tag and 2nd put in where you want to show Facebook comment section in your page.

Go to you page and Copy below code and paste below the body tag.

<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v10.0&appId=427021281892903&autoLogAppEvents=1" nonce="IFt1dfew"></script>

Next step Copy below code and simply paste there where you want to show Facebook comment in your html page.

<!-- fb comment show here  -->
<div class="fb-comments" data-href="http://www.surgeryplanet.com/" data-width="100%" data-numposts="10"></div>
<!-- fb comment show end -->

Next in your page facebook comment is working as like this->

Thanks 🙏🙏

Tagged : / / / /

Fatal error: Maximum execution time of 300 seconds exceeded in C:\xampp\phpMyAdmin\libraries\classes\Dbi\DbiMysqli.php on line 199

Whenever you import file in in database then after some processing time its show you have using Maximum execution time of 300 seconds exceeded will be showing this type of error in your database:

First of all stop your Xampp

Next step : go to config.default.php

Once that’s done get back to finding phpMyadmin config file named something like “config.default.php”. On XAMPP you will find it under “C:\xampp\phpMyAdmin\libraries” folder. Open the file called

config.default.php and set :

$cfg['ExecTimeLimit'] = 0;

Simply paste here..

Once set, restart your MySQL and Apache and go import your database.

Tagged : / / / /

How to Store Data in Pop-Modal in Laravel

In this tutorial I’m going to describe how to store data in bootstrap 4 pop modal in laravel.

composer create-project laravel/laravel employee "5.8"

Step 2-> Go to .env and set up connect with database

DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=popup-modal
DB_USERNAME=root
DB_PASSWORD=

3rd step migrate table

php artisan migrate

Next create migration table as name of employees lets go and create table

php artisan make:migration create_employees_table

Next got to database/migration/create_emoloyees_table and open this file

Simply copy and paste this code

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateEmployeesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('employees', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('fname');
$table->string('lname');
$table->string('email');
$table->string('address');
$table->string('mobile');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('employees');
}
}

Php artisan migrate

Next step create view files in resourses/views/
folder name

empmodel.blade.php

Go to empmodel.blade.php and paste below code

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>


{{-- model start here --}}

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add Employee Detail</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form action="{{ action('EmployeeController@store')}}" method="POST">
{{ csrf_field() }}
<div class="modal-body">

<div class="form-group">
<label>First Name</label>
<input type="text" name="fname" class="form-control" placeholder="Enter first name">
</div>

<div class="form-group">
<label>Last Name</label>
<input type="text" name="lname" class="form-control" placeholder="Enter last name">
</div>

<div class="form-group">
<label>Email</label>
<input type="text" name="email" class="form-control" placeholder="Enter email">
</div>

<div class="form-group">
<label>Address</label>
<input type="text" name="address" class="form-control" placeholder="Enter address">
</div>

<div class="form-group">
<label>Mobile</label>
<input type="text" name="mobile" class="form-control" placeholder="Enter mobile">
</div>

<button type="submit" class="btn btn-primary">Submit</button>

</div>
</form>
</div>
</div>
</div>
{{-- model end here --}}




<br><br><br>
<div class="container">
<h1>Store Data in Pop-modal in laravel</h1>

@if (count($errors) >0)
<div class="alert alert-danger">
<ul>
@foreach($errors->all() as $error)
<li>{{$error}}</li>
@endforeach

</ul>
</div>
@endif

@if (\Session::has('success'))
<div class="alert alert-success">
<p>{{ \Session::get('success') }}</p>

</div>
@endif

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Add Employee
</button>
</div>

{{-- pop model start here --}}

<!-- Button trigger modal -->
{{-- <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button> --}}

<!-- Modal -->


{{-- pop model end here --}}
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>

Lets next go to create model

php artisan make:model Employee

Go to Employee model and paste below code

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Employee extends Model
{
//
}

Next create controller

php artisan make:controller EmployeeController -r

Go to EmployeeController and paste below code

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Employee;

class EmployeeController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('empmodel');
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request,[
'fname' => 'required',
'lname' => 'required',
'email' => 'required',
'address' => 'required',
'mobile' => 'required',
]);

$emps = new Employee;

$emps->fname = $request->input('fname');
$emps->lname = $request->input('lname');
$emps->email = $request->input('email');
$emps->address = $request->input('address');
$emps->mobile = $request->input('mobile');

$emps->save();
return redirect('/employee')->with('success', 'Data saved');


}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}

Next create route go to Route/web.php and paste below code

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
return view('welcome');
});

Route::resource('/employee','EmployeeController');

next go to browser and search

http://127.0.0.1:8000/employee

Now Form is look like this

Fill all the field and click on submit

Next Go to Localhost/phpmyadmin and check your data has been successfully saved

Thanks

stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:

In this tutorial I’m going to solve stream_socket_enable_crypto error please follow these steps

Go to App\config\mail.php

lets open mail.php file and paste below code. 👇👇

‘stream’ => [
‘ssl’ => [
‘allow_self_signed’ => true,
‘verify_peer’ => false,
‘verify_peer_name’ => false,
],
],

And now Got your activation mail successfully.

Tagged : / /

How to Create Virtual Host in Laravel

In this tutorial I’m going to create multiple virtual host in laravel in some easy steps please follow mentioned below.

first stop your xampp 👇

1step-> Go to

C:\xampp\htdocs

ds-admin-ms is your project folder name

ds-admin-ms

2nd step go to

C:\xampp\apache\conf\extra

3rd step Open this file -> httpd-vhosts.conf

4th step Copy below code 👇👇

<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\ds-admin-ms\public"
ServerName ds-admin-ms
ServerAlias ds-admin-ms
<Directory "c:/xampp/htdocs/ds-admin-ms/public">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Next step go to

C:\Windows\System32\drivers\etc

Open this file -> hosts

Simply copy below code 👇

127.0.0.1 		ds-admin-ms
::1

Paste here in C:\Windows\System32\drivers\etc and open this file 👉 hosts

Lets go to xampp and start run

and go to folder -> C:\xampp\htdocs\ds-admin-ms

and open terminal and run

php artisan serve

Next go to browser and paste this

http://ds-admin-ms/

Tagged : / / /

Class ‘App\Http\Controllers\Student’ not found

In this tutorial I’m going to describe how to solve “Class ‘App\Http\Controllers\Student’ not found” if you got this types of error please follow some easy steps

1step this types of error is showing when you’re not using class name whatever you have define below code as like :-

public function index()
{
$students = Student::all();

return view(‘students.dashboard’,compact(‘student’));
}

2nd you have to add your model name above of the StudenController class name

3rd step got your Controller :- StudentController.php

And add model name in the Student Controller class here as like this

use App\Student;

Then refresh your browser and you got solve your errors.

http://127.0.0.1:8000/

Thanks hopefully it will helpful for you. 👍👍

Tagged : / / / /