Category Archives: Blog

Blog

How to get the current URL in Codeigniter

In this How to get the current URL in Codeigniter tutorial I will show you how to get current url in codeigniter. In this tutorial you will learn to get current application url in codeigniter. In this article I will share example to get current url in codeigniter application.

get the current URL in Codeigniter

In this step by step tutorial I will demonstrate you with example how to get current url in codeigniter. Please follow the instruction given below –

Get current URL in codeigniter

In Codeigniter we have a builtin url helper library. In codeigniter url helper allow us to get the current URL using the current_url() method. Below is the example to get the current url using the current_url() method in codeigniter.

Example:-

how to get URL segment in codeigniter

In codeigniter the segment() method is used to get the url segments from the url. Below is the example to retrieve the url segments using the segment() method in codeigniter.

Example:-

Get Current Controller Method Name in codeigniter

In codeigniter the fetch_method() method is used to get the current controller method’s name . Below is the example to get the current controller method name using the fetch_method() method.

Example:-

Autocomplete Textbox in CodeIgniter using Typeahead

In this Autocomplete Textbox in CodeIgniter using Typeahead Js, I will show you how to create a dynamic database driven ajax jquery autocomplete using typeahead js in codeigniter. In this tutorial we will create a dynamic search dropdown autocomplete which will fetch options from database table using bootstrap typeahead js.

The Typeahead JS is a jquery plugin, it is used to create dynamic autocomplete input with several options. In this example you will learn how to implement typeahead autocomplete in codeigniter.

Autocomplete Textbox in CodeIgniter using Typeahead

In this step by step tutorial I will demonstrate how to create a dynamic database driven ajax jquery autocomplete using typeahead js in codeigniter. Please follow the instruction given below:

Step 1: Download Codeigniter
Step 2: Basic Configurations
Step 3: Create a Database in table
Step 4: Connect to Database
Step 5: Create Controller and Model
Step 6: Create Views Files
Step 7: Run The Application

Download Codeigniter

First of all you need to download the latest version of Codeigniter 4.

Basic Configurations

Now, we need to setup some codeigniter basic configurations in your project as following.

Create a Database in table

Now you need to create some database tables in your codeigniter application database. Please use the following sql query to create database tables.

Connect to Database

Now, lets create a MySQL database and connect it with codeigniter application. After creating database we need to set database credential in application’s app/Config/Database.php file.

app/Config/Database.php

Create Controller and Model
In this step we will create a “Student.php” controller file and the “StudentModel.php” model file. Please paste the below code in corresponding file.

app/Models/StudentModel.php

Codeigniter Multiple Files Upload Example

In this Codeigniter Multiple Files Upload Example, I’ll show you how to upload multiple image file in codeigniter. In this codeigniter multiple image upload example, I’ll show you how to validate and upload multiple image file into folder and then save it into database. In this tutorial before saving multiple image into database we will validate image and then save it into directory. Before uploading the image we will validate the image. After successfully uploading multiple images into the folder and saving it in database we will display success message on the screen.

Codeigniter Multiple Files Upload Example

In this step by step tutorial I’ll demonstrate how to upload multiple files in codeigniter with validation. Please follow the steps given below:

Step 1:Create Upload Directory
Step 2:Create The Controller
Step 3:Create The Model
Step 4:Create The View

Create Upload Directory

First of all we have to create assets/uploads/ directory.

Create The Controller

Now, we will create a Multipleimage.php controller. Open Multipleimage.php and put the following code in it.

Create The Model

Lets create the Image_model.php model file as following.

Create The View

Now we will create the image.php view file and put the following code in it.

Multiple database connection in codeigniter

In this Multiple database connection in codeigniter tutorial I will show you how to connect multiple database in codeigniter single application. In this tutorial you will learn to use multiple database connection in codeigniter. You will also learn how to connect multiple database in single codeigniter application.

Multiple database connection in codeigniter

In this tutorial I will share following example to connect or use multiple database in codeigniter application. In this example we will be defining two arrays in application/config/database.php file as following –

application/config/database.php

Now we can access different database connection as following –

how to get last inserted id in codeigniter example

In this how to get last inserted id in codeigniter example tutorial I will show you how to get last inserted id in codeigniter. In this tutorial you will learn to get last inserted id after codeigniter insert query. In this article I will share example to show you how to get last inserted record id on insert query in codeigniter.

how to get last inserted id in codeigniter example

In this step by step tutorial I will demonstrate you with example how to get last inserted id in codeigniter. Below is example to show you to get last record id from MySQL using CodeIgniter.

Example:-

Create PHP Laravel 8 CRUD Web App with MySQL Database

In this Create PHP Laravel 8 CRUD Web App with MySQL Database Tutorial I’ll show you how to create a laravel 8 simple crud application with mysql database in laravel 8. In this tutorial you will learn to create simple laravel 8 crud application example with mysql database. In this article, you will learn how to create fully functional CRUD (Create, Read, Update and Delete) Application In laravel. We will be creating a student crud operation application in laravel 8.

Create PHP Laravel 8 CRUD Web App with MySQL Database

In this step by step guide, we will be creating a simple laravel 8 CRUD application to demonstrate you how to create laravel CRUD operation based application in laravel 8. Please follow the instruction given below:

  1. Creating a Laravel 8|7 Project
  2. Set Up MySQL Database in Laravel
  3. Setting Up Migration and Model
  4. Adding Controller and Creating Routes
  5. Create Views in Laravel with Blade Templates
  6. Create, Store & Validate User Data in MySQL Database
  7. Show Users Data
  8. Edit and Update Data

Creating a Laravel Project

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Get inside the project:

Set Up MySQL Database

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Setting Up Migration and Model

Now, in this step we will create model and migration file. Please run the following command:

Once above command is executed there will be a migration file created inside database/migrations/ directory, just open migration file and update the function up() method as following:

Next, go to app/Models/Student.php file and add the $fillable property in the Student model as following.

Now, run the migration to create database table using following artisan command:

Creating Controller and Routes

Now, lets create a resource controller named StudentController using command given below –

Once the above command executed, it will create a controller file StudentController.php in app/Http/Controllers/ directory. By default, there are seven methods defined in it as following:

index() => shows student list
create() => creates a student using a form
store() => creates a student in the database
show() => shows a specific student
edit() => updates the student data using a form
update() => updates the student data using a form
destroy() => removes a particular student

Open the StudentController.php file and put the following code in it.

Configure Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Run the following command in terminal to check the various routes for our CRUD app.


Create Views in Laravel with Blade Templates

In this step we will create blade view files for our student CRUD operations. Go to resources/views folder and create the following blade templates in our Laravel project.

layout.blade.php
index.blade.php
create.blade.php
edit.blade.php

Configure Bootstrap in Laravel

Create, Store & Validate User Data in MySQL Database

Add the following code in the resources/views/create.blade.php file.

To generate a new user, we are using cerate() mehtod, which is specified in the ShowController.php file.

Show Users Data

Add the following code in the resources/views/index.blade.php file.

Edit and Update Data

To edit and update data in MySQL database we are going to add the following code inside the resources/views/edit.blade.php file.

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

Create Student :-


Students List :-

Install Laravel 8 with Composer on macOS, Ubuntu and Windows

In this Install Laravel 8 with Composer on macOS, Ubuntu and Windows tutorial I will show you how to install latest Laravel 8 version with Composer on your system. In this tutorial you will learn to install latest Laravel 8 with Composer on your local system. In this article I will guide you through example how to setup Laravel 8 project using Composer on your localhost system.

Install Laravel 8 with Composer on macOS, Ubuntu and Windows

In this step by step tutorial I will demonstrate you with example how to install Laravel 8 version with Composer on your system. Please follow the instruction given below:

  • HTTP Client
  • Laravel Airlock
  • Custom Eloquent Casts
  • Blade Component Tags & Improvements
  • Route Caching Speed Improvements, etc.

Install Composer using Homebrew

Run the following command to check the installed Composer version.

You will see the similar output:

Install Laravel Project

Create a fresh laravel project, download and install Laravel 8 using the below command

Once the installation proecess is completed then run the following command to get into the Laravel project folder.

Run Laravel Application

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

Laravel application by default starts on port 8000 however you can change it by executing followign command.

Now, open the following URL in browser to see the output –

Laravel 8 Multiple Images Upload with Validation Example

In this Laravel 8 Multiple Images Upload with Validation Example Tutorial, I will show you how to upload multiple image with validation in laravel 8. In this tutorial you will learn to upload multiple image in laravel with validation and save into folder and then save it into database. In this example before saving multiple image into database we will validate image and then save it into directory. Before uploading the image we will validate the image. After successfully uploading multiple images into the folder and saving it in database we will display success message on the screen.

Laravel 8 Multiple Images Upload with Validation Example

In this step by step tutorial I’ll demonstrate example of multiple image upload with Validation in laravel 8. Please follow the step given below:

  1. Create Project
  2. Database Configuration
  3. Create Model and Migrations
  4. Create Controller
  5. Create Routes
  6. Create Blade File

Create Laravel Project

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Now switch to the project directory.

Database Configuration

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Create Model and Migrations

Now, in this step we will create model and migration file. Please run the following command:

Once above command is executed there will be a migration file created inside database/migrations/ directory, open migration file and update the function up() method as following:

Now put the following code inside the app/Models/Image.php file.

Now, run the migration to create database table using following artisan command:

Create Image Uploading Controller

Now, lets create a controller named FileUpload using command given below –

Once the above command executed, it will create a controller file FileUpload.php in app/Http/Controllers/ directory. Open the FileUpload.php file and put the following code in it.

app/Http/Controllers/FileUpload.php

The createForm() function will display image upload from in the view, and the the fileUpload() method will handle uploading, storing and validation in the image uploading controller.

Create Routes in Laravel

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Create Blade Template

In this step we will create blade view file for uploading multiple images. Create resources\views\image-upload.blade.php file and add the following code.

Start The Application

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

How to Check Laravel Version via CLI and Application File

In this How to Check Laravel Version via CLI and Application File tutorial, I will show you how to check laravel version using laravel cli or application file. In this tutorial you will learn to check laravel version using laravel cli command and in laravel application file.

How to Check Laravel Version via CLI and Application File

There are following two ways to check the version of your Laravel application.

  • Check Laravel Version Using the Command
  • Check Laravel Version in Files

Check Laravel Version using the Command

If you want to check laravel version using artisan command then switch to the project directory and run the following command to check laravel version:

Check Laravel Version in Application File

In this method we will check laravel version from laravel application files. Go to your project root directory. And follow the path

You can see the version number of Laravel at around line no 36, and the version is defined in the const VERSION = ‘….’.

Laravel 8 Socialite OAuth Login with Twitter Example

In this Laravel 8 Socialite OAuth Login with Twitter Example tutorial I’ll show you how to integrate socialite Twitter social login in laravel application. In this tutorial you will learn to integrate Twitter login in laravel. In this article we will integrate login  with Twitter in laravel 8 application. This tutorial is step by step guide for you on how to integrate Twitter social login in laravel 8 using socialite package.

As we all know that users are not much interested in filling up long registration form to register with any application. Allowing users to login with their social media accounts is quick and powerful way to get registered/verified users for your laravel application. Allowing users to login with their social media accounts makes registration/login process much easier, it also encourages more users to register for your application.

Laravel 8 OAuth Login with Twitter Example

In this step by step tutorial I will demonstrate you with example how to integrate Twitter login with your laravel application. Please follow the instruction given below:

  • Step 1: Install Laravel Fresh App
  • Step 2: Setup Database
  • Step 3: Download Socialite Package
  • Step 4:Create Twitter App
  • Step 5: Add Code In Model and Migration
  • Step 6: Add Routes for Twitter App
  • Step 7: Create Controller & Methods
  • Step 8: Install Laravel Livewire and Jetstream Packages
  • Step 9: Update Login View
  • Step 10: Run Development Server

Step 1: Install Laravel Fresh App

First of all we need to create a fresh laravel project, download and install Laravel using the below command

Step 2: Setup Database

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Step 3: Download Socialite Package

In this step we will Install Socialite Package via Composer using following command:

After Installing ‘socialite’ package, we need to add service provider and alias in config/app.php file as following.

config/app.php

In this step we will create Twitter App for Twitter social login. Use the link provided to create twitter app.

After successfully create an app in twitter and get credentials from twitter dashboard, Set client id and client secret config/service.php file :

config/service.php

Step 5: Add Code In Model and Migration

Now, in this step we will create model and migration file. Please run the following command:

Next step, Go to app/database/create_users_table.php and put the below code here :

Step 6: Add Routes for Twitter App

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Step 7: Create Controller

Now, lets create a controller named TwitterSocialController using command given below –

Now, go to app/http/controllers directory and open TwitterSocialController.php file. And put the following code in TwitterSocialController.php file:

Step 8: Install Laravel Livewire and Jetstream Packages

Now, you need to run the following command to install livewire and jetstream package:

Next, install Jetstream with Livewire:

Now, you need to install and build your NPM dependencies and migrate your database:

Now, run the migration to create database table using following artisan command:

Step 9: Update Login View

Now, go to views/auth/ directory and open login.blade.php file, and update the following code into it:

Step 10: Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

Laravel 7/6 Form Submit Validation Example Tutorial

In this Laravel 7/6 Form Submit Validation Tutorial I’ll show you how to submit form with validation in laravel 7 and 6. In this article I will also show you how to validate form data before submit in laravel. In this tutorial you will learn to submit form with validation in laravel.In this tutorial I will demonstrate you how to validate form data on the server-side before submit on controller and store data into database in laravel.

In this tutorial you will also learn to submit form data on the controller and validate using laravel validation rules.

Laravel 7/6 Form Submit Validation Example Tutorial

In this step by step tutorial I will share example to submit form data with validation in laravel. Please follow the instruction given below:

  • Install Laravel Fresh Setup
  • Setup Database
  • Make Migration file with Model
  • Make Route
  • Create Controller & Methods
  • Create Blade View
  • Start Development Server

1). Install Laravel Fresh Setup

First of all we need to create a fresh laravel project, download and install Laravel using the below command

2). Setup Database

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

3). Make Migration file with Model

Now, in this step we will create model and migration file. Please run the following command:

Now go to Go to /database/migrations and open create_contacts_table.php file. Then add the below function into create_contacts_table.php file :

Before we run php artisan migrate command go to app/providers/AppServiceProvider.php and put the below code :

Now, in this step we will create model and migration file. Please run the following command:

Now go to app/Contact.php file and add the fillable properties like this :

4). Make Route

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

5). Create Controller

Now, lets create a controller named ContactController using command given below –

After successfully create controller go to app/controllers/http//ContactController.php and put the below code :

6). Create Blade view

Now, we will create a blade view file name contact.blade.php and put the following code in it:

7). Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

Laravel where Day, Date, Month, Year, Time, Column

In this laravel eloquent query methods tutorial, I will show you how to use various laravel eloquents methods. In this tutorial you will learn about laravel eloquents methods like where, whereDate, whereRaw, whereMonth, whereYear, whereIn, whereNotIn, whereNull, whereNotNull, whereTime, havingRaw, whereBetween, whereNotBetween and laravel pluck.

Laravel where Day, Date, Month, Year, Time, Column

In this step by step tutorial I will demonstrate you use and application of laravel eloquents methods like where, whereDate, whereRaw, whereMonth, whereYear, whereIn, whereNotIn, whereNull, whereNotNull, whereTime, havingRaw, whereBetween, whereNotBetween and laravel pluck.

Laravel All Where Eloquent Queries Methods

Where() Function :

Below is simple example of laravel eloquent where() method:

orWhere() Function :

Below is simple example of laravel eloquent orWhere() method:

WhereBetween Function :

Below is simple example of laravel eloquent WhereBetween() method:

WhereNotBetween Function :

Below is simple example of laravel eloquent WhereNotBetween() method:

WhereIn() Function :

Below is simple example of laravel eloquent WhereIn() method:

WhereNull() Function :

Below is simple example of laravel eloquent WhereNull() method:

WhereNotNull() Function :

Below is simple example of laravel eloquent WhereNotNull() method:

WhereNotIn() Function :

Below is simple example of laravel eloquent WhereNotIn() method:

WhereDate() Function :

Below is simple example of laravel eloquent WhereDate() method:

WhereMonth() Function :

Below is simple example of laravel eloquent WhereMonth() method:

WhereDay() Function :

Below is simple example of laravel eloquent WhereDay() method:

WhereYear() Function :

Below is simple example of laravel eloquent WhereYear() method:

WhereTime() Function :

Below is simple example of laravel eloquent WhereTime() method:

WhereColumn() Function :

Below is simple example of laravel eloquent WhereColumn() method:

WhereRaw() Function :

Below is simple example of laravel eloquent WhereRaw() method:

OrderBy Function :

Below is simple example of laravel eloquent OrderBy() method:

SelectRaw() Function :

Below is simple example of laravel eloquent SelectRaw() method:

HavingRaw() Function :

Below is simple example of laravel eloquent HavingRaw() method:

Laravel Pluck () Function:

Below is simple example of laravel eloquent pluck() method:

Laravel Delete () Functions:

Below is simple example of laravel eloquent Delete() method: