Category Archives: Laravel

Laravel Tutorials

Create Controller And Model Laravel 7/6 Using Command

In this Create Controller And Model Laravel 7/6 Using Command tutorial I will show you how to Create Controller And Model Using Command In laravel. In this tutorial you will learn to create or generate controller and model using command in laravel. In this article we will learn about laravel artisan command to create controller and model. In this article I will demonstrate you with example to create controller and model using laravel command.

Create Controller And Model Laravel 7/6 Using Command

In this step by step tutorial I will show you how to create or generate controller and model using command in laravel. Please follow the instructions given below:

Create model command

Below is example command to create laravel model. Please  Use the php artisan make model for creating a model using the command line (CLI) :

The above command will create a photo model with following code:

Create Controller command

Below is example command to create laravel controller. Please  Use the php artisan make controller for creating a controller using the command line (CLI) :

The above command will create a controller named photoController with following code:

Create a Resource Controller Command

Below is example command to create a resource controller. Please  Use the php artisan make controller with –resource option for creating a resource controller:

Below is default resource controller code generated with the above command. It has already created some methods like index, update, edit, destroy, etc. It looks like this:

Command For Create Model and Controller

Below is example command to create laravel model and controller together.

How to Add a Column or Columns To Existing Table In Laravel

In this How to Add a Column or Columns To Existing Table In Laravel tutorial, I will show you how to add a culumn or columns to existing table in laravel. In this tutorial you will learn add one or multiple columns to database table using migration in laravel. In this article I will show you different ways you can alter existing table schema using migrations in laravel.

How to Add a Column or Columns To Existing Table In Laravel

In this step by step guide I will demonstrate you how to add new columns or columns to an existing table using Laravel migration.

Laravel Migration:

  • Add a single Column an existing table
  • Add Multiple Columns in Existing Table
  • Available Column Types

Add a single Column an existing table

Below is the example command to add single column to existing table.

It will create an add_type_to_notes file in the migration folder. It should be like this-

Run Migration Command

Now, run the following command to migrate table schema,

Add Multiple Columns in Existing Table

Below is the example command to add multiple column to existing table.

The above command will create a migration file, so go to database/migration folder and open your file and add column according to you:


Finally, run the below-given command for adding columns in your database table:

Available Column Types

Laravel 7/6 Custom Login Registration Example Tutorial

In this Laravel 7/6 Custom Login Registration Example Tutorial I will show you how to create custom login and registration system in laravel. In this tutorial you will learn to create custom login and registration system in laravel. Though laravel comes with default authentication system we can also create custom login, registration and logout functionality. In the step by step custom authentication tutorial I will show you to create controller, routes, model, and blade views files for custom login, registration and logout functionality.

Laravel 7/6 Custom Login Registration Example Tutorial

  • Install Laravel Fresh New Setup
  • Setup Database Credentials
  • Make Route
  • Create Controller & Methods
  • Create Blade View
  • Run Development Server
  • Conclusion

1). Install Laravel Fresh New 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.

Next,  we will migrate the table into the database using the below command :

3). 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

4). Create Controller

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

After successfully create controller go to app/controllers/AuthController.php and update the below code in your controller:

5). Create Blade view

Now, we will create three-blade view files as following:

login blade.php


registration blade.php

dashboard.blade.php

Next, we will create a  style.css file inside app/public folder and updates the below code in your file:

6). 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 Multiple File Upload With Validation Example

In this Laravel multiple file Upload with validation example, we will learn how to upload and save multiple file in laravel. In this laravel multiple file upload example, I’ll show you how to validate upload multiple file into folder and then save it into database. In this tutorial before saving file into database we will validate file and then save it into directory. Before uploading the files we will perform server side validation. After successfully file upload into the database and folder we will display success message on the screen.

Laravel 7/6 Multiple File Upload With Validation Example

  • Download Laravel Fresh New Setup
  • Setup Database Credentials
  • Generate Migration & Model
  • Make Route
  • Create Controller & Methods
  • Create Blade View
  • Run Development Server

1). Download Laravel Fresh New Setup

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

2). Setup Database Credentials

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). Generate Migration & Model

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

The above command will create a model name file and also create a migration file for the file table. After successfully run the command go to database/migrations file and put the below here :


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

4). Add 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 FileController using command given below –

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

6). Create Blade view

Now we will create a blade view file. Go to app/resources/views and create one file name file.blade.php :

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 7/6 Stripe Payment Gateway Integration Example

In this Laravel 7/6 stripe payment gateway integration tutorial, I’ll show you how to integrate stripe payment gateway in laravel 7. In this tutorial you will learn to integrate stripe in laravel 7. In this step by step tutorial I’ll share laravel 7 stripe integration example.

Stripe Payment Gateway

Stripe is one of the most popular payment gateway, that allows us to accept payment worldwide. Stripe is very simple, hassle free and easy to integrate payment gateway. Integrating stripe payment gateway with laravel is a breeze. After integrating stripe in laravel you will be able to collect payment via simple payment form which allow customer to provide card information like card number, expiry date and a CVC code.

Laravel 7/6 Stripe Payment Gateway Integration Example

In this tutorial, you will learn to integrate stripe payment gateway in your laravel 7 project. Follow this step by step tutorial to learn stripe payment gateway integration in laravel 7.

Laravel 7/6 Stripe Payment Gateway Integration Example

  • Step 1: Install Laravel Fresh Setup
  • Step 2: Install stripe Package
  • Step 3: Set Secret Credential
  • Step 4: Make Route
  • Step 5: Create Controller
  • Step 6: Create Blade View file
  • Step 7: Run Development Server

Step 1: Install Laravel Fresh Project

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

Step 2: Install Stripe package

Now, we need to install stripe-laravel package in our project. Open your terminal and switch to project directory and use the following composer command to install stripe-laravel package.

After that, we need to register the provider and aliases. Go to the app/config/app.php and put the below lines here :

Step 3: Set Secret Credential

Now, we need to set stripe key and secret key in our project’s .env file. In stripe dashboard switch to the test mode and get the stripe key and secret. Now, open .env file located in project’s root folder and set the stripe key and secret as following –

.env file

You will also need to set up the Stripe API key, Let’s open or create the config/services.php file, and add or update the 'stripe' array as following:

Step 4: Make Route

After this, we need to add following two routes in “routes/web.php” to display barcode. Lets open “routes/web.php” file and add following route.

routes/web.php

Step 5: Create Controller

Now, lets create a payment controller using following command

Go to app/Http/Controller/StripeController and put the below code :

Step 6: Create Blade View file

In this step, we will create view/blade file to accept stripe payment. Lets create astripe.blade.php” file in “resources/views/” directory and put the following code in it.

resources/views/stripe.blade.php

Step 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 –

Testing Card Credential

Laravel Get Current URL With Parameters

In this get the current URL with parameters tutorial I will show you how to get the current URL , parameters, domain etc details from current url in laravel. In this tutorial you will learn how can you get the current URL with parameters, previous URL, global URL, current URL Path in laravel.

Laravel Get Current URL With Parameters

How to Get Current Request URL

In the following example we have fetched the current url:

Use global url function

In the following example we have fetched the current url using global url function.

In the following example we have fetched the current url using current function.

In the following example we have fetched the current url using current full URL with query string parameters

How to get Current URL path

In the following example we have fetched the current url path.

Get the previous URL in Laravel

In the following example we have fetched the previous url.

Laravel Check Old Password and Updating a New Password

In this Laravel Check Old Password and Updating a New Password tutorial I will show you how to check old password and update with new password in laravel. In this tutorial you will learn to check old password and update new password in laravel. In this article I will demonstrate you how can you easily update the new password with old password validation.

Laravel change password old password validation

In this example we have a function to change user password checking old password. In the below function we have to pass old password, new password and confirm password.

Example:-

Laravel 7 FullCalendar Ajax Example Tutorial

In this Laravel fullcalendar example tutorial I’ll show you how to display events on the calendar using fullcalendar components in laravel apps. In this tutorial you will learn to display events on the calendar using fullcalendar in laravel. This tutorial you will also learn to show dynamic event data on calendar using  fullcalendar components in laravel.

Laravel 7 FullCalendar Ajax Example Tutorial

  • Install Laravel App
  • Setup Database
  • Generate Migration & Model
  • Make Route
  • Create Controller & Methods
  • Create Blade View
  • Run Development Server

1). Install Laravel App

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). Generate Migration & Model

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

The above command will create a model name Event and also create a migration file for the Events table.Now go to database/migrations folder and open create_events_table.php file. Then put the following code into create_events_table.php file, as follow:

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

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 FullCalendarController using command given below –

After successfully create controller go to app/controllers/FullCalendarController.php and update the below code :

6). Create Blade view

In this step we will create a blade file. Go to app/resources/views and create one file name fullcalendar.blade.php

Put the script on fullcalendar.blade.php, after the closing of the body tag

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 7/6 Flash Message Example

In this Laravel Flash Message Example tutorial I will show you how to create or implement flash message in laravel application. In this tutorial you will learn to implement flash message in laravel. While working with laravel application we come to situations where we want to show/display various flash success and error messages. In this example we will be using sweet alert js to display various type of flash messages or notifications.

Laravel 7/6 Flash Message Example

In this step by step guide I will demonstrate you how you can implement success or error messages with sweet alert js in your laravel application.

Laravel Flash Message

In this tutorial we will learn to following types of flash messages

  • Laravel Success Flash Message
  • Laravel Error Flash Message
  • Laravel Flash Success With Sweet alert
  • Laravel Flash Error With Sweet alert

Laravel Success Flash Message

Below is example to display success message:

Below is example to send and display success message on redirect method:

Laravel Error Flash Message

Below is example to display error message:

Below is example to send and display error message on redirect method:

Laravel Flash Success With Sweet Alert

If you want to show a success message with sweet alert, use the following code in your blade files:

Laravel Flash Error With Sweet Alert

If you want to show an error message with a sweet alert use the following code in your blade files:

How to Create Custom Helper In Laravel

In this How to Create Custom Helper In Laravel tutorial I will show you how to create custom helper in laravel. In this tutorial you will learn to create custom helper file in laravel. With custom helper file you can define functions that you can reuse in your laravel application.

What Laravel Custom Helper

In laravel, custom helper file helps you to reduce the re-writing the same code again and again. With custom helper file you can define the custom helper functions that you can use anywhere in your laravel project.

How to Create Custom Helper In Laravel

In this step by step tutorial I demonstrate you how to create custom helper file in laravel project. I will also show you how to define custom helper function and to call them in laravel application:

Create helpers.php File

In custom helper file you can define your own functions and call anywhere in your laravel  project. Go to App directory and create a new file helpers.php like this app/helpers.php.

Add File Path In composer.json File

In this step, we will add helper file path in composer.json file. Go to root directory and open composer.json file and put the following code into the file:

composer.json

Now, go to command prompt and type the given command:

Now you can use your custom helper functions by calling this functions remove_special_char(), random_code() etc.

Now, I’ll show you how to use custom helper function in your laravel project:

Example 1

Example 2

How to Generate sitemap.xml file in Laravel

In this How to Generate sitemap.xml file in Laravel tutorial I will show you how to create sitemap.xml file in laravel application. In this tutorial you will learn to create sitemap.xml file for you laravel website. Sitemap.xml file is important for any website, it is used by search engines for indexing the website. In this step by step guide I will demonstrate you how to create search engine or seo friendly sitemap.xml for laravel websites.

How to Generate sitemap.xml file in Laravel

In this tutorial you will learn to create search engine friendly sitemap.xml in laravel. Here I will demonstrate you step by step to create a sitemap.xml file in laravel.

Create a Sitemap Controller

In this step we will create SitemapController using following artisan command:

Now, we will create a index method to generate XML.

The sitemap.xml file


The next step is generating URL for the existing files, this will mean, the controller getting four methods which are similar as illustrated below,


Now we will create a product.blade.php inside the folder name sitemap and put the following code in it. Your sitemap/product.blade.php should look like this:


NOw, we will define some routes as following

Laravel 7/6 CKEditor with Image Upload

In this Laravel 7/6 CKEditor with Image Upload tutorial I will show you how to install and use CKEditor with image upload in laravel. In this tutorial, you will learn to install CKEditor in laravel using the command line. In this step by step guide I also show you how to upload images and files in laravel with CKEditor.

Laravel 7/6 CKEditor with Image Upload

  • Install Laravel
  • Install CKEditor Package in Laravel
  • Register CKEditor package in Laravel
  • Publish the Ckeditor package by command
  • Create Route
  • Generate Controller
  • Create Blade View
  • Upload and Insert Image in laravel using CKEditor

1. Install Laravel

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

2. Install CKEditor In Laravel

In this step, we will install CKEditor Package via the composer dependency manager. Use the following command to install CKEditor Package.

3. Register CKEditor package in Laravel

Now, we will register the package in laravel. Go to config/app.php and put the following line to the providers array.

4. Publish the Ckeditor package by command

Now run following command to copy some of the files and folders from ‘vendor\unisharp\laravel-ckeditor’ to ‘public\vendor\unisharp\laravel-ckeditor’.

5. Create 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

6. Generate Controller

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

After successfully run the above command and create a controller file. Next open your controller and put the below code into your file.

7. Create Blade View

Now we go resource/views and create a file name ckeditor.blade.php. After this we will create a blade file now put the following code in it:

Note:- If the package of ckeditor is having some problem installing your Laravel web application. Then you add the following cdn file to your blade view file:

8. Upload and Insert Image in laravel using CKEditor

Now we have to enable image upload option in ckeditor as following:

Now we will create a route for upload the image in laravel using CKEditor.

Next, open your terminal and run the below command:

Next, we will put the below method in our controller name CKEditor. This method will store the image or files in the server and return the image URL.