Codeigniter For Validation With Error Message Example

Hi Guys

In this tutorial,i will show you how to implement server side validation example,it can easyli Codeigniter Server Side Form Validation With Error Message in this example,normal validation two sides like server side and client side, i will give you simple example of form validation in codeigniter application. we will use form_validation library for add form validation with error message display in codeigniter.

we can use defaulut following validation rules of codeigniter.We can use default following validation rules of codeigniter

  • required
  • regex_match
  • matches
  • differs
  • is_unique
  • min_length
  • max_length
  • exact_length
  • greater_than
  • You can see more from here
Codeigniter Validation Rules. Exmaple

So here i gave you full example of form validation in codeigniter application. i created simple form with first name, last name, email and Mobile Number like contact us form and i set server side validation.

Step:1 Download Codeigniter Project

Here in this step we will download the latest version of Codeigniter, Go to this link Download Codeigniter download the fresh setup of codeigniter and unzip the setup in your local system xampp/htdocs/ . And change the download folder name "demo"

Step:2 Basic Configurations

Here in this step,we will set the some basic configuration on config.php file, so let’s go to application/config/config.php and open this file on text editor.

Set Base URL like this

$config['base_url'] = 'http://localhost/demo/';
Step:3 Create Database With Table

Here in this step,we need to create database name demo, so let’s open your phpmyadmin and create the database with the name demo. you can use the below sql query for creating a table in your database.

CREATE TABLE users (
    id int(11) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
    first_name varchar(100) NOT NULL COMMENT 'Name',
    last_name varchar(100) NOT NULL COMMENT 'Name',
    email varchar(255) NOT NULL COMMENT 'Email Address',
    contact_no varchar(50) NOT NULL COMMENT 'Contact No',
    created_at varchar(20) NOT NULL COMMENT 'Created date',
    PRIMARY KEY (id)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='datatable demo table' AUTO_INCREMENT=1;
Step:4 Setup Database Credentials

Here in this step,we need in this step connect our project to database. go to the application/config/ and open database.php file in text editor.We need to setup database credential in this file like below.

$db['default'] = array(
  'dsn' => '',
  'hostname' => 'localhost',
  'username' => 'root',
  'password' => '',
  'database' => 'demo',
  'dbdriver' => 'mysqli',
  'dbprefix' => '',
  'pconnect' => FALSE,
  'db_debug' => (ENVIRONMENT !== 'production'),
  'cache_on' => FALSE,
  'cachedir' => '',
  'char_set' => 'utf8',
  'dbcollat' => 'utf8_general_ci',
  'swap_pre' => '',
  'encrypt' => FALSE,
  'compress' => FALSE,
  'stricton' => FALSE,
  'failover' => array(),
  'save_queries' => TRUE
);
Step:5 Create Controller

Here in this step,we create a controller name Users.php. In this controller we will create some method/function. We will build some of the methods like :

-> Index() – This is used to display a form.

-> post_validate() – This is used to validate data on server side and store a data into database.

<?php
class Users extends CI_Controller {
  
    public function __construct()
    {
        parent::__construct();
        $this->load->library(array('form_validation','session'));
        $this->load->helper(array('url','html','form'));
        $this->load->database();
    }
  
    public function index()
    {
      $this->load->view('form_validation');
    }
    public function post_validate()
    {
 
        $this->form_validation->set_rules('first_name', 'First Name', 'required');
        $this->form_validation->set_rules('last_name', 'Last Name', 'required');
        $this->form_validation->set_rules('contact_no', 'Contact No', 'required');
        $this->form_validation->set_rules('email', 'Email', 'required');
 
        $this->form_validation->set_error_delimiters('<div class="error">','</div>');
        $this->form_validation->set_message('required', 'Enter %s');
 
        if ($this->form_validation->run() === FALSE)
        {  
            $this->load->view('form_validation');
        }
        else
        {   
          $data = array(
             'first_name' => $this->input->post('first_name'),
             'last_name' => $this->input->post('last_name'),
             'contact_no' => $this->input->post('contact_no'),
             'email' => $this->input->post('email'),
 
           );
   
            $insert = $this->db->insert('users', $data);
            if ($insert) {
               $this->load->view('success');
            } else {
               redirect( base_url('users') ); 
            }
   
            }
 
    }
 
}
Step:6 Create Views

Now in this step we will create a form_validation.php , go to application/views/ folder and create form_validation.php file. Here put the below html code for showing form.

<!DOCTYPE html>
<html>
<head>
  <title>Codeigniter Form Validation - nicesnippets.com </title>
 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
</head>
<body>
 <div class="container">
    <br>
    <div class="row">
    <div class="col-md-9">
    <form action="<?php echo base_url('users/post_validate') ?>" method="post" accept-charset="utf-8">
      <div class="form-group">
        <label for="formGroupExampleInput">First Name</label>
        <input type="text" name="first_name" class="form-control" id="formGroupExampleInput" placeholder="Please enter first name">
        <?php echo form_error('first_name'); ?> 
      </div> 
 
      <div class="form-group">
        <label for="formGroupExampleInput">Last Name</label>
        <input type="text" name="last_name" class="form-control" id="formGroupExampleInput" placeholder="Please enter last name">
        <?php echo form_error('last_name'); ?>  
      </div>
 
      <div class="form-group">
        <label for="email">Email Id</label>
        <input type="text" name="email" class="form-control" id="email" placeholder="Please enter email id">
        <?php echo form_error('email'); ?> 
      </div>   
 
      <div class="form-group">
        <label for="mobile_number">Mobile Number</label>
        <input type="text" name="contact_no" class="form-control" id="contact_no" placeholder="Please enter mobile number" maxlength="10">
        <?php echo form_error('contact_no'); ?> 
      </div>
 
      <div class="form-group">
       <button type="submit" id="send_form" class="btn btn-success">Submit</button>
      </div>
    </form>
    </div>
    <div class="col-md-3">
      <?php $this->load->view('layout/media_left_side_bar'); ?>
    </div>
    </div>
</div>
</body>
</html>
Step:7 Success Views

Now in this step we need to create success.php file, so go to application/views/ and create success.php file. And put the below code here.

<!DOCTYPE html>
<html>
<head>
  <title>Codeigniter Form Validation - nicesnippets.com </title>
 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
 <h1> Thank You for Registered</h1>
</div>
</body>
</html>
Start Server And Run Program

For start development server, Go to the browser and hit below the url.

http://localhost/demo/users

I hope it can help you...

PHP Ajax Image Upload With Preview Example

Hi Guys,

In this tutorial, i will give you simple example of ajax image upload with preview in php. Uploading image via an jquery AJAX in php. I have added code for doing PHP image upload with AJAX without reloading the page.

xI use jQuery AJAX to implement image upload. There is a form with file input field and a submit button. On submitting the form with the selected image file, the AJAX script will be executed. In this code, it sends the upload request to PHP with the uploaded image. PHP code moves the uploaded image to the target folder and returns the image HTML to show the preview as an AJAX response.

The following code shows the HTML for the image upload form. On submitting this form the AJAX function will be called to send the request to the PHP image upload code.

Create Form form.php
<html>
<head>
   <title>PHP AJAX Image Upload</title>
   <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
   <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.css">
</head>
<body>
<div class="container">
   <div class="col-md-6 offset-md-3">
      <div class="card">
         <div class="card-title p-1 bg-success">
            <h6>PHP AJAX Image Upload</h6>
         </div>
         <div class="card-body">
            <form id="uploadForm" action="upload.php" method="post">
               <div class="col-md-12 bg-light mb-2 text-center">
                  <div id="targetLayer">No Image</div>
               </div>
               <div class="form-group">
                  <input name="userImage" type="file" class="form-controller" />
               </div>
               <input type="submit" value="Submit" class="btn btn-success" />
            </form>
         </div>
      </div>
   </div>
</div>
</div>
</body>
<script type="text/javascript">
$(document).ready(function (e) {
   $("#uploadForm").on('submit',(function(e) {
      e.preventDefault();
      $.ajax({
           url: "upload.php",
         type: "POST",
         data:  new FormData(this),
         contentType: false,
         cache: false,
         processData:false,
         success: function(data)
          {
            $("#targetLayer").html(data);
          },
              error: function() 
          {
          }            
      });
	}));
});
</script>
</html>
Create Upload Fille upload.php
<?php
  if(is_array($_FILES)) {
    if(is_uploaded_file($_FILES['userImage']['tmp_name'])) {
      $sourcePath = $_FILES['userImage']['tmp_name'];
      $targetPath = "images/".$_FILES['userImage']['name'];
      if(move_uploaded_file($sourcePath,$targetPath)) {
?>
<img class="img-fluid" width="100%" height="100" src="<?php echo $targetPath; ?>" />
<?php
  }
    }
      }
?>

it code is a redy php ajax image upload with preview and the run code.

it will help you..

Laravel Livewire Fullcalendar Integration Example

Hi Guys,

Today, I will learn you how to use fullcalendar with livewire example. We will explain step-by-step laravel livewire fullcalendar integration. you can easily make livewire fullcalendar integration in laravel. we will describe laravel livewire fullcalendar integration.

Here, I will give you full example for simply livewire fullcalendar integration in laravel native as bellow.

Step 1 : Install Laravel App

In First step, We need to get fresh laravel version application using bellow command. So Let's open terminal and run bellow command.

composer create-project --prefer-dist laravel/laravel blog
Step 2 : Setup Database Configuration

After successfully install laravel app thenafter configure databse setup. We will open ".env" file and change the database name, username and password in the env file.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=Enter_Your_Database_Name
DB_USERNAME=Enter_Your_Database_Username
DB_PASSWORD=Enter_Your_Database_Password
Step 3 : Install Livewire

In this step, You will simply install livewire to our laravel application using bellow command:

composer require livewire/livewire
Step 4 : Create items Table and Model

In this step we have to create migration for items table using Laravel php artisan command, so first fire bellow command:

php artisan make:model Event -m

After this command you have to put bellow code in your migration file for create items table.

following path: /database/migrations/2021_04_10_102325_create_events_table.php
<?php

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

class CreateEventsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('events', function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->string('start');
            $table->timestamps();
        });
    }

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

Now we require to run migration be bellow command:

php artisan migrate

After you have to put bellow code in your model file for create items table.

following path:/app/Models/Event.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Event extends Model
{
    use HasFactory;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'title',
        'start',
    ];
}
Step:5 Create Route

In thi step,now, we need to add resource route for livewire fullcalendar integration in application. so open your "routes/web.php" file and add following route.

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Livewire\Calendar;
use App\Models\Event;
/*
|--------------------------------------------------------------------------
| 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::view('/', 'home');

Livewire::component('calendar', Calendar::class);
Step 6 : Create Component

Now, You can create livewire component using bellow command, So Let's run bellow command to create calendar form component:

php artisan make:livewire calendar
Now they created fies on both path:
app/Http/Livewire/Calendar.php
resources/views/livewire/calendar.blade.php
Now first file we will update as bellow for Calendar.php file. app/Http/Livewire/Calendar.php
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\Event;

class Calendar extends Component
{
    public $events = '';

    public function getevent()
    {       
        $events = Event::select('id','title','start')->get();

        return  json_encode($events);
    }

    /**
    * Write code on Method
    *
    * @return response()
    */ 
    public function addevent($event)
    {
        $input['title'] = $event['title'];
        $input['start'] = $event['start'];
        Event::create($input);
    }

    /**
    * Write code on Method
    *
    * @return response()
    */
    public function eventDrop($event, $oldEvent)
    {
      $eventdata = Event::find($event['id']);
      $eventdata->start = $event['start'];
      $eventdata->save();
    }

    /**
    * Write code on Method
    *
    * @return response()
    */
    public function render()
    {       
        $events = Event::select('id','title','start')->get();

        $this->events = json_encode($events);

        return view('livewire.calendar');
    }
}
Step 7: Create View

Here, we will create blade file for call fullcalendar route. in this file we will use @livewireStyles, @livewireScripts so let's add it

resources/views/home.blade.php
<html>
<head>
    @livewireStyles
</head>
<body>
    <livewire:calendar />
    @livewireScripts
    @stack('scripts')
</body>
</html>

after,I will create calendar componet blade file.

resources/views/livewire/calendar.blade.php
<style>
    #calendar-container{
        width: 100%;
    }
    #calendar{
        padding: 10px;
        margin: 10px;
        width: 1340px;
        height: 610px;
        border:2px solid black;
    }
</style>

<div>
  <div id='calendar-container' wire:ignore>
    <div id='calendar'></div>
  </div>
</div>

@push('scripts')
    <script src='https://cdn.jsdelivr.net/npm/fullcalendar@5.3.1/main.min.js'></script>
    
    <script>
        document.addEventListener('livewire:load', function() {
            var Calendar = FullCalendar.Calendar;
            var Draggable = FullCalendar.Draggable;
            var calendarEl = document.getElementById('calendar');
            var checkbox = document.getElementById('drop-remove');
            var data =   @this.events;
            var calendar = new Calendar(calendarEl, {
            events: JSON.parse(data),
            dateClick(info)  {
               var title = prompt('Enter Event Title');
               var date = new Date(info.dateStr + 'T00:00:00');
               if(title != null && title != ''){
                 calendar.addEvent({
                    title: title,
                    start: date,
                    allDay: true
                  });
                 var eventAdd = {title: title,start: date};
                 @this.addevent(eventAdd);
                 alert('Great. Now, update your database...');
               }else{
                alert('Event Title Is Required');
               }
            },
            editable: true,
            selectable: true,
            displayEventTime: false,
            droppable: true, // this allows things to be dropped onto the calendar
            drop: function(info) {
                // is the "remove after drop" checkbox checked?
                if (checkbox.checked) {
                // if so, remove the element from the "Draggable Events" list
                info.draggedEl.parentNode.removeChild(info.draggedEl);
                }
            },
            eventDrop: info => @this.eventDrop(info.event, info.oldEvent),
            loading: function(isLoading) {
                    if (!isLoading) {
                        // Reset custom events
                        this.getEvents().forEach(function(e){
                            if (e.source === null) {
                                e.remove();
                            }
                        });
                    }
                }
            });
            calendar.render();
            @this.on(`refreshCalendar`, () => {
                calendar.refetchEvents()
            });
        });
    </script>
    <link href='https://cdn.jsdelivr.net/npm/fullcalendar@5.3.1/main.min.css' rel='stylesheet' />
@endpush

Now we are ready to run our example so run bellow command for quick run:

php artisan serve
Now you can open bellow URL on your browser:
http://localhost:8000/
Preview
Add Event Fullcalendar
Drag And Drop Fullcalendar

It will help you..

Laravel Validation digits Example

Hi Guys,

Today, I will learn you to create validation digits in laravel.we will show example of laravel validation digits.The field under validation must be numeric and must have an exact length of value.

Here, I will give you full example for simply Validation digits in laravel bellow.

solution
$request->validate([
  'rank' => 'required|digits:10',
]);
Route : routes/web.php
Route::get('form/create','FromController@index');
Route::post('form/store','FromController@store')->name('form.store');
Controller : app/Http/Controllers/BlogController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Blade;
use App\Models\User;
use App\Models\Post;

class FromController extends Controller
{   
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function create()
    {
        return view('form');
    }
    
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function store(Request $request)
    {
        $request->validate([
          'rank' => 'required|digits:10'
        ]);

        dd('done');
    }
}
View : resources/views/form.php
<!DOCTYPE html>
<html>
<head>
  <title>From</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha512-MoRNloxbStBcD8z3M/2BmnT+rg4IsMxPkXaGh2zD6LGNNFE80W3onsAhRcMAMrSoyWL9xD7Ert0men7vR8LUZg==" crossorigin="anonymous" />
  <scr Validation digitst src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></scr Validation digitst>
  <scr Validation digitst src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></scr Validation digitst>
</head>
<body class="bg-dark">
  <div class="container">
    <div class="row">
      <div class="col-md-6 offset-3">
        <div class="card mt-5">
          <div class="card-header">
            <div class="row">
              <div class="col-md-9">
                 Laravel Validation digits Example
              </div>
              <div class="col-md-3 text-right">
                <a href="{{ route('form') }}" class="btn btn-sm btn-outline-primary">Back</a>
              </div>
            </div>
          </div>
          <div class="card-body">
            @if (count($errors) > 0)
                  <div class="row">
                      <div class="col-md-12">
                          <div class="alert alert-danger alert-dismissible">
                              <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                              @foreach($errors->all() as $error)
                              {{ $error }} <br>
                              @endforeach      
                          </div>
                      </div>
                  </div>
                @endif
              <form action="{{ route('from.store') }}" method="post">
                @csrf
                <div class="row">
                  <div class="col-md-12">
                    <div class="form-group">
                      <label>Rank No:</label>
                      <input name="rank" type="text" class="form-control">
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-md-12">
                    <button class="btn btn-block btn-success">Submit</button>
                  </div>
                </div>
              </form>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>
</html>

It will help you...

Fullcalendar V4 Disabled Drag And Drop Event Example

Hi Guys,

This example is focused on fullcalendar v4 disable drag and drop event. This article will give you simple example of full calendar v4 drag and drop disable. you will learn how to disable drag and drop fullcalendar vs4 event. you will learn disable drag and drop fullcalendar v4 . Let's get started with disable drag and drop in fullcalendar v4.

In this blog, I will explain how to disabled event disabled drag and drop in fullcalendar. We will show example of fullcalendar v4 disabled drag and drop. you can simple copy bellow code and use in your project. It's pretty easy and simple example of fullcalendar v4 disabled event drag and drop .In this example, you can easy to create disabled event drag and drop in fullcalendar v4.

Here the example of disabled drag and drop in fullcalendar.

Disabled Drag And Drop Event Code:

This determines if the events can only drag and drop Enables/disables at a time.

droppable: false
Or

This determines if the events can be dragged and resized. Enables/disables both at the same time.

editable:false
Example: 1 Now In this example droppable method using disables drag and drop events in fullcalendar.
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<link href='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/core/main.min.css' rel='stylesheet' />
<link href='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/daygrid/main.min.css' rel='stylesheet' />
<link href='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.css' rel='stylesheet' />
<link href='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/list/main.min.css' rel='stylesheet' />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.css">
<style>
  html, body {
    font-size: 14px;
    background: #e2e2e2;
    overflow: hidden;
  }
  #calendar{
    width: 80%;
    margin-left: 100px;
    box-shadow: 0px 0px 10px #000;
    padding:15px; 
    background: #fff;
  }
  #calendar-container {
    position: fixed;
    top: 0%;
    text-align: center;
    left: 10%;
    right: 10%;
    bottom: 20%;
  }
</style>
</head>
<body style="width: 100%">
  <div id='calendar-container'>
  <h1>Fullcalendar V4 Disabled Drag And Drop Event - Nicesnippets.com</h1>
    <div id='calendar'></div>
  </div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/core/main.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/interaction/main.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/daygrid/main.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/list/main.min.js'></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
  document.addEventListener('DOMContentLoaded', function() {
    var calendarEl = document.getElementById('calendar');

    var calendar = new FullCalendar.Calendar(calendarEl, {
      plugins: [ 'interaction', 'dayGrid', 'timeGrid', 'list' ],
      height: 'parent',
      header: {
        left: 'prev,next today',
        center: 'title',
        right: 'dayGridMonth',
      },
      defaultView: 'dayGridMonth',
      navLinks: true,
      droppable: false,
      eventLimit: true,
      disableDragging: false,
      events: [
        {
          title: 'Day Event',
          start: '2020-03-01',
        },
        {
          title: 'Day Event 2',
          start: '2020-03-03',
        },
        {
          title: 'Day Event 3',
          start: '2020-03-11',
        },
        {
          title: 'Day Event 4',
          start: '2020-03-15',
        },
        {
          title: 'Day Event 4',
          start: '2020-03-20',
        },
      ]
    });
    calendar.render();
  });
</script>
</body>
</html>
Example: 2

Now in this example,if the events can be dragged and resized disables both at the same time.

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<link href='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/core/main.min.css' rel='stylesheet' />
<link href='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/daygrid/main.min.css' rel='stylesheet' />
<link href='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.css' rel='stylesheet' />
<link href='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/list/main.min.css' rel='stylesheet' />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.css">
<style>
  html, body {
    font-size: 14px;
    background: #e2e2e2;
    overflow: hidden;
  }
  #calendar{
    width: 80%;
    margin-left: 100px;
    box-shadow: 0px 0px 10px #000;
    padding:15px; 
    background: #fff;
  }
  #calendar-container {
    position: fixed;
    top: 0%;
    text-align: center;
    left: 10%;
    right: 10%;
    bottom: 20%;
  }
</style>
</head>
<img src="">
<body style="width: 100%">
  <div id='calendar-container'>
  <h1>Fullcalendar V4 Disabled Drag And Drop Event - Nicesnippets.com</h1>
    <div id='calendar'></div>
  </div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/core/main.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/interaction/main.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/daygrid/main.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/list/main.min.js'></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
  document.addEventListener('DOMContentLoaded', function() {
    var calendarEl = document.getElementById('calendar');

    var calendar = new FullCalendar.Calendar(calendarEl, {
      plugins: [ 'interaction', 'dayGrid', 'timeGrid', 'list' ],
      height: 'parent',
      header: {
        left: 'prev,next today',
        center: 'title',
        right: 'dayGridMonth',
      },
      defaultView: 'dayGridMonth',
      navLinks: true,
      editable: false,
      droppable: false,
      eventLimit: true,
      disableDragging: false,
      events: [
        {
          title: 'Day Event',
          start: '2020-03-01',
        },
        {
          title: 'Day Event 2',
          start: '2020-03-03',
        },
        {
          title: 'Day Event 3',
          start: '2020-03-11',
        },
        {
          title: 'Day Event 4',
          start: '2020-03-15',
        },
        {
          title: 'Day Event 4',
          start: '2020-03-20',
        },
      ]
    });
    calendar.render();
  });
</script>
</body>
</html>

It will help you...

Fullcalendar V4 Remove Event Example

Hi Guys,

In this example, i will show you fullcalendar v4 remove event example. This article goes in detailed on fullcalendar v4 delete event. We will use fullcalendar remove event example code. i would like to share with you fullcalendar v4 remove event basic example.

I will show the example of fullcalendar v4 remove event.We will show basic example of fullcalendar v4 remove event. we will create fullcalendar delete event using version 4 you can get code of remove eventin fullcalendar. we give you example of step by step fullcalendar remove event, you can simple copy bellow code and use in your project. It's pretty easy and simple example of fullcalendar v4 delete event.In this example, you can easy to create fullcalendar v4 remove event.

Here the example of fullcalendar v4 remove event

Remove Event Code:
  var event = calendar.getEventById(EventID);
    event.remove();
Example

Now this example in create basic fullcalendar remove event for full code:

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<link href='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/core/main.min.css' rel='stylesheet' />
<link href='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/daygrid/main.min.css' rel='stylesheet' />
<link href='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.css' rel='stylesheet' />
<link href='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/list/main.min.css' rel='stylesheet' />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.css">
<style>
  html, body {
    font-size: 14px;
    background: #e2e2e2;
    overflow: hidden;
  }
  #calendar{
    width: 80%;
    margin-left: 100px;
    box-shadow: 0px 0px 10px #000;
    ping:15px; 
    background: #fff;
  }
  #calendar-container {
    position: fixed;
    top: 0%;
    text-align: center;
    left: 10%;
    right: 10%;
    bottom: 20%;
  }
</style>
</head>
<img src="">
<body style="width: 100%">
  <div id='calendar-container'>
  <h1>Fullcalendar v4 Remove Event Example - Nicesnippets.com</h1>
   <button id="btn-delete-event" class="btn btn-danger mb-2">Click Remove Event</button> 
    <div id='calendar'></div>
  </div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/core/main.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/interaction/main.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/daygrid/main.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/list/main.min.js'></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
  document.EventListener('DOMContentLoaded', function() {
    var calendarEl = document.getElementById('calendar');

    var calendar = new FullCalendar.Calendar(calendarEl, {
      plugins: [ 'interaction', 'dayGrid', 'timeGrid', 'list' ],
      height: 'parent',
      header: {
        left: 'prev,next today',
        center: 'title',
        right: 'dayGridMonth',
      },
      defaultView: 'dayGridMonth',
      navLinks: true,
      editable: true,
      eventLimit: true,
      events: [
        {
          id: '1',
          title: 'All Day Event',
          start: '2020-02-01',
        },
        {
          id: '2',
          title: 'All Day Event 2',
          start: '2020-02-02',
        },
        {
          id: '3',
          title: 'All Day Event 3',
          start: '2020-02-03',
        }
      ],
    });

    $('#btn-delete-event').click(function(){
        var event = calendar.getEventById('2');
        alert("Are You Remove Event "+event.title);
        event.remove();
    });

    calendar.render();
  });
</script>
</body>
</html>

It Will help You...

Fullcalendar v4 Add Event Tutorial

Hi Guys,

Today our leading topic is fullcalendar v4 add event example. This tutorial will give you simple example of fullcalendar v4 add event. this example will help you fullcalendar add event example code. this example will help you fullcalendar v4 add event basic example.

I will show the example of fullcalendar v4 add event.I will show basic example of fullcalendar v4 add event. we will create fullcalendar add event using version 4 you can get code of add eventin fullcalendar. we give you example of step by step fullcalendar add event, you can simple copy bellow code and use in your project. It's pretty easy and simple example of fullcalendar v4 add event.In this example, you can easy to create fullcalendar v4 add event.

Here the example of fullcalendar v4 add event

Add Event Code:
 calendar.addEvent({
    title: 'Add Event....',
    start: 2020-02-18,
    allDay: true
  });
Example

Now in this example in create basic fullcalendar add event for full code:

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<link href='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/core/main.min.css' rel='stylesheet' />
<link href='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/daygrid/main.min.css' rel='stylesheet' />
<link href='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.css' rel='stylesheet' />
<link href='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/list/main.min.css' rel='stylesheet' />
<style>
  html, body {
    font-size: 14px;
    background: #e2e2e2;
  }
  #calendar{
    width: 80%;
    margin-left: 100px;
    box-shadow: 0px 0px 10px #000;
    padding:15px; 
    background: #fff;
  }
  #calendar-container {
    position: fixed;
    top: 0%;
    text-align: center;
    left: 10%;
    right: 10%;
    bottom: 20%;
  }
</style>
</head>
<body>
  <div id='calendar-container'>
  <h1>Fullcalendar v4 Add Event Example  - Nicesnippets.com</h1>
    <div id='calendar'></div>
  </div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/core/main.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/interaction/main.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/daygrid/main.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/list/main.min.js'></script>
<script>
  document.addEventListener('DOMContentLoaded', function() {
    var calendarEl = document.getElementById('calendar');

    var calendar = new FullCalendar.Calendar(calendarEl, {
      plugins: [ 'interaction', 'dayGrid', 'timeGrid', 'list' ],
      header: {
        center: 'addEventButton'
      },
      customButtons: {
        addEventButton: {
          text: 'add event...',
          click: function() {
            var dateStr = prompt('Enter a date in YYYY-MM-DD format');
            var date = new Date(dateStr + 'T00:00:00'); // will be in local time

            if (!isNaN(date.valueOf())) { // valid?
              calendar.addEvent({
                title: 'dynamic event',
                start: date,
                allDay: true
              });
              alert('Great. Now, update your database...');
            } else {
              alert('Invalid date.');
            }
          }
        }
      }
    });

    calendar.render();
  });
</script>
</body>
</html>

It Will help you...

How To Check Current Date Between Two Dates In Php?

Hi guys,

In this artical, I will show you how to check current date between two dates in php. current date between two date check in using php.

You can check date between two dates using php .You can get current date then start date and end date between date then return true otherwise false return.

Solution 1
<?php
$today = date('Y-m-d');
$today=date('Y-m-d', strtotime($today));

$stratDate = date('Y-m-d', strtotime("01/01/2018"));
$endDate = date('Y-m-d', strtotime("01/12/2019"));

if (($today >= $stratDate) && ($today <= $endDate)){
    echo "true";
}else{
    echo "false";  
}

If return true you current date in between two dates, return false not between in two date


Solution 2
<?php
$stratDate = date('Y-m-d', strtotime("01/01/2018"));
$endDate = date('Y-m-d', strtotime("01/12/2019"));

if ((date('Y-m-d', time()) >= $stratDate) && (date('Y-m-d', time()) <= $endDate)){
    echo "true";
}else{
    echo "false";  
}

If return true you current date in between two dates, return false not between in two date

It will help you...

PHP Dropzone Add Download Button Example

Hi Guys,

Today,I will learn you how to use dropzone file upload in php.we will help you to give example of dropzone add download link example. We will use php dropzone add download button. We will use add download button in dropzone js php. Follow bellow tutorial step of dropzone download file on click.

If you need to add download uploaded file in dropzone then We will show you how to add download button on uploaded file with ajax request. we will add download link and it will download file from server in dropzone.js.dropzone provide success function and we will append a tag with uploaded file path. here we will use php with dropzone to download file from server.

Here, I will give you full example for simply dropzone add download button using php as bellow.

Step 1: Create index.php file

In this step,we have to create index.php file in our root folder and copy bellow code and put on that file. In this file i use cdn for bootstrap, jquery, dropzone css and js.

I will write click event for button and when you click on that button then and then images will upload to server.

<!DOCTYPE html>
<html>
<head>
  <title>PHP - Dropzone Add Download Button Example</title>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css" />
  <link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.0.1/min/dropzone.min.css" rel="stylesheet">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.2.0/min/dropzone.min.js"></script>
</head>
<body>
   
<div class="container">
  <div class="row">
    <div class="col-md-12">
      <h2>PHP - Dropzone Add Download Button Example </h2>
      <form action="upload.php" enctype="multipart/form-data" class="dropzone" id="image-upload">
        <input type="hidden" name="request" value="add">
        <div>
          <h3>Upload Multiple Image By Click On Box</h3>
        </div>
      </form>
    </div>
  </div>
</div>
   
<script type="text/javascript">
  
    Dropzone.autoDiscover = false;
  
    var myDropzone = new Dropzone(".dropzone", { 
       maxFilesize: 10,
       acceptedFiles: ".jpeg,.jpg,.png,.gif",
       success: function (file, response) {
        if(response != 0){
           var anchorEl = document.createElement('a');
           anchorEl.setAttribute('href',response);
           anchorEl.setAttribute('target','_blank');
           anchorEl.innerHTML = "<br>Download File";
           file.previewTemplate.appendChild(anchorEl);
        }
       }
    });
   
</script>
  
</body>
</html>
Step 2: create upload.php file

In this step,we have to create upload.php file in our root folder. In this file i write image upload folder code.

upload.php
<?php
  
$uploadDir = 'upload';
  
$tmpFile = $_FILES['file']['tmp_name'];
$filename = $uploadDir.'/'.$_FILES['file']['name'];
move_uploaded_file($tmpFile,$filename);
  
echo $filename;
  
?>
Step 3: Create upload folder

Here in this step , I have to just create "upload" folder for store images. You can also give different name from uploads, But make sure also change on upload.php file.

Now I am ready to run this example, so just run bellow command on root folder for run your project.

php -S localhost:9000

Now you can open bellow url on your browser:

http://localhost:8000
It will help you...

Laravel 8 Factory Example Tutorial


Hi Guys In this tutorial, I will learn how to generate dummy records in your database table using tinker factory of Laravel 8. As I know testing is very important part of any web development project. Sometime we may require to add hundreds records in your users table, OR maybe thousands of records. Also think about if you require to check pagination. then you have to add some records for testing. So what you will do it at that that moment, You will add manually thousands of records ? What you do ?. If you add manually thousands of records then it can be take more time. Here,Laravel 8 have composer package "laravel/tinker" that we will provide you to generate dummy records by using their command. So Laravel 8 by default take "laravel/tinker" package for project. Also they provide by default one factory for user table. You can check path here : database/factories/. In this folder you can add your different factory for different model. Generate Dummy Products:
php artisan tinker
Product::factory()->count(5)->create()
Here, I will give you full example for simply create dummy data using tinker factory using laravel 8 as bellow. Step 1 : Install Laravel 8 Application we are going from scratch, So we require to get fresh Laravel application using bellow command, So open your terminal OR command prompt and run bellow command:
composer create-project --prefer-dist laravel/laravel blog
Step 2: Create Model and Migration Here this step, we will create one model and migration name Product. Use the below following command and create it
php artisan make:model Product -m
next,open products migration file and put the below code. Path: /database/migrations/2020_02_03_095534_create_products_table.php
<?php

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

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

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('products');
    }
}
Next, go to app/Product.php and open Product model file and put the below code. here following path of model fille Path:/app/Models/Product.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    use HasFactory;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'detail'
    ];
}
Step 3: Create Factory In this setp,I will create ProductFactory in following command As you see above command for user, But you can not do same for other model. If you want to do this then you have to add factory for that model. So i am going to give you full example of factory from scratch.
php artisan make:factory ProductFactory --model=Product
I have Product model with products table. Now we want to add dummy records for Product model. So we have to add factory like as bellow : database/factories/ProductFactory.php
<?php

namespace Database\Factories;

use App\Models\Product;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

class ProductFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = Product::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'name' => $this->faker->name,
            'detail' => $this->faker->text,
        ];
    }
}
after run command in terminal
composer dump-autoload
and
php artisan tinker
Product::factory()->count(5)->create()
It Will help you...

Laravel Custom Artisan command Example

Hi Friends,

Today,I will learn you how to create custom command in laravel .It's better if we make our own artisan command for like project setup, create new admin Student etc in our laravel application. If we create custom command then we can make project setup like create one admin Student, run migration, run seeder and etc. In this post i give you example, how to create console commands in laravel project.

In this example I will create custom command for create new admin Student. This custom command will ask your name, email and password.

Custom command
php artisan students:create
This command through we will create new admins. So first fire bellow command and create console class file.
php artisan make:command StudentCommand --command=student:create
Next this command you can find one file StudentCommand class in console directory. so one that file and put bellow code. app/Console/Commands/StudentCommand.php
<php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\Student;
use Hash;

class StudentCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'students:create';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $input['name'] = $this->ask('Your name?');
        $input['email'] = $this->ask('Your email?');
        $input['password'] = $this->secret('What is the password?');
        $input['password'] = Hash::make($input['password']);

        Student::create($input);

        $this->info('Student Create Successfully.');
    }
}
After, Now I need to register this command class in Kernel.php file, so open file and add class this way:
<?php	
namespace App\Console;


use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;


class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        Commands\StudentCommand::class,
    ];
    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        

    }
}

Now we are ready to use or custom command, you fire bellow command and check you can find command in the list this way "students:create".

php artisan list
php artisan students:create

It will help you..

Laravel 8 Image Upload Tutorial

Hi Guys, Today,I will learn you how to create Image Upload in laravel 8. We will show example of image upload in laravel 8. you can easyliy create Image Upload in laravel 8 I am going to show you about image upload in laravel 8. this example will help you laravel 8 upload image to database. This article goes in detailed on how to upload and display image in laravel 8. Here, Creating a basic example of laravel 8 image upload with preview. I created simple form with file input. So you have to simple select image and then it will upload in "images" directory of public folder. So you have to simple follow bellow step and get image upload in laravel 8 application. Here, I will give you full example for simply Image Upload using Laravel 8 as bellow. Step 1 : Install Laravel 8 Application we are going from scratch, So we require to get fresh Laravel application using bellow command, So open your terminal OR command prompt and run bellow command:
composer create-project --prefer-dist laravel/laravel blogImageUpload
cd blogImageUpload
Step 2: Create Routes In next step, we will add new two routes in web.php file. One route for generate form and another for post method So let's simply create both route as bellow listed:
Route::get('/upload-image', [ImageUploadController::class, 'index'])->name('image.upload.index');
Route::post('/upload-image/store', [ImageUploadController::class, 'store'])->name('image.upload.store')
Step 3: Create Controller here this step now we should create new controller as ImageUploadController,So run bellow command for generate new controller
php artisan make:controller ImageUploadController
At last step we need to create imageUpload.blade.php file and in this file we will create form with file input button. So copy bellow and put on that file.
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ImageUploadController extends Controller
{ 
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
      return view('imageUpload');
    }

    /**
     * Write code on Method
     *
     * @return response()
     */
    public function store(Request $request)
    {
      $request->validate([
            'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:1024',
        ]);
    
        $imageName = time().'.'.$request->image->extension();
     
        $request->image->move(public_path('images'), $imageName);
  
        / store image in database from here /
    
        return redirect()->back()->with('success','Image uploaded successfully.')->with('image',$imageName);
    }
}
Store Image in Storage Folder
$request->image->storeAs('images', $imageName);
// storage/app/images/file.png
Store Image in Public Folder
$request->image->move(public_path('images'), $imageName);
// public/images/file.png
Store Image in S3
$request->image->storeAs('images', $imageName, 's3');
Step 4: Create Blade File At last step we need to create imageUpload.blade.php file and in this file we will create form with file input button. So copy bellow and put on that file. resources/views/imageUpload.blade.php
<!DOCTYPE html>
<html>
<head>
    <title>Laravel 8 Multiple File Upload - Mywebtuts.com</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" integrity="sha256-NuCn4IvuZXdBaFKJOAcsU2Q3ZpwbdFisd5dux4jkQ5w=" crossorigin="anonymous" />
    <link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-md-6 offset-3 mt-5">
            <div class="card mt-5">
                <div class="card-header text-center bg-primary">
                    <h2 class="text-white"> <strong>Multiple File Upload</strong></h2>
                </div>
                <div class="card-body">
                  @if ($message = Session::get('success'))
		            <div class="alert alert-success alert-block">
		                <button type="button" class="close" data-dismiss="alert">×</button>
		                <strong>{{ $message }}</strong>
		            </div>
		          @endif
		            @if (count($errors) > 0)
		                <ul class="alert alert-danger pl-5">
		                  @foreach($errors->all() as $error)
		                     <li>{{ $error }}</li> 
		                  @endforeach
		                </ul>
		            @endif
		            <form method="post" action="{{ route('multiple.file.upload.store') }}" enctype="multipart/form-data">
		              @csrf
		              <div class="input-group file-div control-group lst increment" >
		                <input type="file" name="files[]" class="myfrm form-control">
		                <div class="input-group-btn"> 
		                  <button class="btn btn-success add-btn" type="button"><i class="fldemo fa fa-plus"></i></button>
		                </div>
		              </div>
		              <div class="clone hide">
		                <div class="file-div control-group lst input-group" style="margin-top:10px">
		                  <input type="file" name="files[]" class="myfrm form-control">
		                  <div class="input-group-btn"> 
		                    <button class="btn btn-danger" type="button"><i class="fldemo fa fa-close"></i></button>
		                  </div>
		                </div>
		              </div>
		              <div class="row">
		                <div class="col-md-12 text-center mt-4">
		                  <button type="submit" class="btn btn-success rounded-0"><i class="fa fa-save"></i> Save</button>
		                </div>
		              </div>
		          </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function() {
      $(".add-btn").click(function(){
          var lsthmtl = $(".clone").html();
          $(".increment").after(lsthmtl);
      });
      $("body").on("click",".btn-danger",function(){
          $(this).parents(".file-div").remove();
      });
    });
</script>
</body>
</html>
Now we are ready to run our custom validation rules example so run bellow command for quick run:
php artisan serve
Now you can open bellow URL on your browser:
http://localhost:8000/upload-image
It will help you...

Laravel Run Artisan Command From Controller Example

Hi Guys,

Today,I will describe you how to you can execute artisan commands from controller in laravel. we will explain laravel run artisan command from controller.we are call artisan command from controller in laravel. it will run artisan command from controller laravel.

You can easy execute artisan command from controller in laravel. we can do it using Artisan facade. Laravel Artisan facade that way we can easily run all artisan command with argument.we can do it using Artisan facade. Laravel Artisan facade that way we can easily run all artisan command with argument. you can also use this example in laravel.

Artisan facade have two method call() and queue(), queue() through we can simply make process in queue like email sending etc. So let's see simple example with route. In this example we run "php artisan migrate" command using artisan facade. Here i bellow example you can learn how you can run artisan commands from route.

Exmaple:1

Here In this example, Here bellow example you can call artisan migrate command from controller

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function index()
{   
    /* php artisan migrate */
    \Artisan::call('migrate');

    dd('all migration run successfully');
}
Exmaple:2

In this example, you can call artisan cache clear command from controller

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function index()
{   
    /* php artisan cache:clear */
    \Artisan::call('cache:clear');

    dd('cache clear successfully');
}
Exmaple:3

bellow example, You can call artisan run seeder command from controller

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function index()
{   
    /* php artisan migrate */
    \Artisan::call('db:seed', array('--class' => "AdminSeeder"));

    dd('Seeder run successfully');
}
Exmaple:4

In this example, you can call artisan run configration clear command from controller

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function index()
{   
    /* php artisan config:clear */
    \Artisan::call(config:clear);

    dd('Configuration cache cleared!');
}

It will help you...

Laravel Validation Custom Error Messages Tutorial

 

Hi Guys,

Today, I will learn you how to use validation custom error messages in laravel. we will show explain of laravel validation custom error messages. I will explain step by step laravel validation custom error messages.we will implement a laravel custom validation message in controller. This article goes in detailed on laravel form validation custom error messages.

I will show you three way to set custom error messages with laravel validation. we will add custom error messages in laravel app. sometime I need to change default laravel validation error message to his own.

Example 1: Directly in Controller Code

In this example, we can directly change from controller method, i think if you want to make it quick then this option will be perfect.

StudentController.php
<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Student;

class StudentController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $students = Student::all();
        return view('students.index', compact('students'));
    }


    /**
     * 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',
            'email' => 'required|email|unique:students,email',
            'password' => 'required|same:confirm_password'
            ],
            [ 'name.required' => 'The :attribute field can not be blank value.']);


        $input = $request->all();
        $input['password'] = bcrypt($input['password']);

        Student::create($input);

        return redirect(route('students.index'));
    }
}
Example 2: Using Custom Request

In this example,we have to create custom request and then you can use it in your controller, this method is better way of laravel, so can run following command to create student form request.

	php artisan make:request StudentFormRequest
app/Http/Requests/StudentFormRequest.php
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;

class StudentFormRequest extends FormRequest
{
    /**
     * Determine if the student is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return false;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required',
            'email' => 'required|email|unique:students,email',
            'password' => 'required|same:confirm_password'
            ];
    }
    /**
     * Get the error messages for the defined validation rules.
     *
     * @return array
     */
    public function messages()
    {
        return [
            'name.required' => 'The :attribute field can not be blank value',
        ];
    }
}
StudentController.php
all();
        $input['password'] = bcrypt($input['password']);

        Student::create($input);

        return redirect(route('students.index'));
    }
}
Example 3: Using Language File

In this example, we will set custom messages by directly on laravel set default files. but it will change in your whole project. So here bellow i added controller validation code for my student module like as bellow.

StudentController.php
<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Student;

class StudentController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $students = Student::all();
        return view('students.index', compact('students'));
    }

    /**
     * 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',
            'email' => 'required|email|unique:students,email',
            'password' => 'required|same:confirm_password'
            ]);

        $input = $request->all();
        $input['password'] = bcrypt($input['password']);

        Student::create($input);

        return redirect(route('students.index'));
    }
}

Now i want to change my validation error message for "name" field, so open "validation.php" file and change like as bellow:

resources/lang/en/validation.php
....
'custom' => [
        'name' => [
            'required' => 'The :attribute field can not be blank value.',
        ],
    ],
....

It will help you...