Category Archives: Laravel

Laravel Tutorials

Laravel 6 Image Upload With Validation

Laravel 6 Image Upload With Validation

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

Install Laravel 6

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

Configure Database In .env file

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.

.env

Generate Migration

Now, we have to define table schema for photos table. Open terminal and let’s run the following command to generate a migration file to create photos table in our database.

Once this command is executed you will find a migration file created under “database/migrations”. lets open migration file and put following code in it –

Run Migration

Now, run following command to migrate database schema.

After, the migration executed successfully the photos table will be created in database along with migrations, password_resets and users table.

Create Model

Next, we need to create a model called Photo using below command.

Once, the above command is executed it will create a model file Photo.php in app directory.

Create Controller

Now, lets create a controller for simple image uploading. Create a controller named ImageUploadController using command given below –

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

app/Http/Controllers/simple_image_upload/ImageUploadController.php

Here In the controller, we have following methods –

index() :- It displays Image Upload Form along with Uploaded Image

store() :- To Upload and Save Image in database .

Note:- Before uploading any file make sure you have created following two directory in the public folder called profile_images.

Create Blade / View Files

In this step, we will create view/blade file to generate and display Image Upload Form. Lets create a blade file “index.blade.php” in “resources/views/simple_image_upload/” directory and put the following code in it respectively.

resources/views/simple_image_upload/index.blade.php

Create Routes

After this, we need to add following routes in “routes/web.php” file along with a resource route. Lets open “routes/web.php” file and add following route.

routes/web.php

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 –

http://localhost:8000/simple-image-upload

Output:-

laravel-simple-image-upload-with-validation-1

After Image Upload Screen Output:-

laravel-simple-image-upload-with-validation-2

Laravel 5.8 Simple Image Upload With Validation

Laravel 5.8 Simple Image Upload With Validation

In this Laravel Simple Image Upload with validation example, we will learn how to upload and save image in laravel. This laravel image upload example is works with laravel version 6, 5.8 & 5.7.

In this laravel simple image upload example, I’ll show you how to validate upload image into folder and then save it into database. In this tutorial before saving image into database we will validate image and then save it into directory using. Before uploading the image we will perform server side validation. After successfully image upload into the database and folder we will display success message on the screen.

Install Laravel 5.8

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

Configure Database In .env file

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.

.env

Generate Migration

Now, we have to define table schema for photos table. Open terminal and let’s run the following command to generate a migration file to create photos table in our database.

Once this command is executed you will find a migration file created under “database/migrations”. lets open migration file and put following code in it –

Run Migration

Now, run following command to migrate database schema.

After, the migration executed successfully the photos table will be created in database along with migrations, password_resets and users table.

Create Model

Next, we need to create a model called Photo using below command.

Once, the above command is executed it will create a model file Photo.php in app directory.

Create Controller

Now, lets create a controller for simple image uploading. Create a controller named ImageUploadController using command given below –

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

app/Http/Controllers/simple_image_upload/ImageUploadController.php

Here In the controller, we have following methods –

index() :- It displays Image Upload Form along with Uploaded Image

store() :- To Upload and Save Image in database .

Note:- Before uploading any file make sure you have created following two directory in the public folder called profile_images.

Create Blade / View Files

In this step, we will create view/blade file to generate and display Image Upload Form. Lets create a blade file “index.blade.php” in “resources/views/simple_image_upload/” directory and put the following code in it respectively.

resources/views/simple_image_upload/index.blade.php

Create Routes

After this, we need to add following routes in “routes/web.php” file along with a resource route. Lets open “routes/web.php” file and add following route.

routes/web.php

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 –

http://localhost:8000/simple-image-upload

Output:-

laravel-simple-image-upload-with-validation-1

After Image Upload Screen Output:-

laravel-simple-image-upload-with-validation-2

Laravel 6 Multiple Authentication Using Middleware

Laravel 6 Multiple Authentication Using Middleware

Install Laravel 6

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

Configure Database In .env file

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.

Migrations and User Model

After installing laravel, you will see the some migration files created inside database/migrations directory for creating default create users table and password reset table. Open app/database/create_users_table.php migration file and add/update the following field for admin.

After you added a column “is_admin” to user table run the migration using following command.

After this, go to app/User.php and add is_admin to fillable attribute in the User Model.

Authentication Scaffolding

Laravel comes with in-built basic authentication system, use the below command to generate default authentication scaffolding –

This command will generate required Controller files, views and add routes in our web.php routes file that are required for basic authentication system.

Create Admin Middleware

Now, we will create a middleware that authenticate users. This middleware will help to make sure who can access the admin area or who can access the normal user area. Use the following command to generate a middleware for Admin.

Next, open app/Http/ Middleware/Admin.php file, and here in handle() method implement the logic to authenticate users like below.

Now, we need to register admin route in $routeMiddleware property in the app/Http/Kernel.php file. Lets open app/Http/Kernel.php file and update the $routeMiddleware property like below –

Set Admin Protected Route

Next, create the route for admin. Open the routes/web.php file and add the following code in it.

routes/web.php

Create Controller Methods

Open the app/Http/Controllers/HomeController.php controller file and create two separate methods to handle admin and normal users.

app/Http/Controllers/HomeController.php

Create Blade/View

Now we will have two separate view files, first is for home page and second is for after login admin page. Open the resources/views/home.blade.php file and update the following code.

resources/views/home.blade.php

Here, if(auth()->user()->is_admin == 1) is used to check user is a normal user or an admin user, it will navigate to the admin area. Otherwise, it will redirect to users area.

Now, create a view file called admin.blade.php in the root of the views folder, and add the following code to it.

resources/views/admin.blade.php

Start Development Server

Start the development server using following artisan command –

In order to test laravel multi auth system first register a user through laravel register and then change the is_admin=1; and try to login again.

User Home 1 :-

laravel-multi-auth-2

After Login Admin Page :-

laravel-multi-auth-1

User Home 2 :-

laravel-multi-auth-3

Laravel 6 Intervention Image Upload Using Ajax

Laravel 6 Intervention Image Upload Using Ajax

In this Laravel Intervention Image Upload Using Ajax example, we will learn how to upload and resize image using jquery ajax. In this tutorial I have used Intervention Image Package to upload and resize the image using jquery ajax and then save image into the database. This laravel image upload example is works with laravel version 6, 5.8 & 5.7 .

In this laravel image upload example, I’ll show you how to upload image into folder and then save it into database. In this tutorial before saving image into database we will resize the image and create it’s thumbnail image and then save it into thumbnail directory using the image intervention package.

Before uploading the image we will validate it using server side validation. In this example we will be uploading the image using jquery ajax without page refresh and reload. After successfully image upload into the database and folder we will display original image along with its thumbnail image (resize image).

Basic Usage Of Intervention Image Package

Create Instance :-

Resize Image to Fixed Size :-

Resize Image Width:-

Resize Image Height:-

Resize Width with Aspect Ratio:-

Resize Height with Aspect Ratio:-

Prevent Possible Upsizing:-

Install Laravel 6

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

Configure Database In .env file

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.

.env

Install Image Intervention Package

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

Register Package

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

config/app.php

Generate Migration

Now, we have to define table schema for photos table. Open terminal and let’s run the following command to generate a migration file to create photos table in our database.

Once this command is executed you will find a migration file created under “database/migrations”. lets open migration file and put following code in it –

Run Migration

Now, run following command to migrate database schema.

After, the migration executed successfully the photos table will be created in database along with migrations, password_resets and users table.

Create Model

Next, we need to create a model called Photo using below command.

Once, the above command is executed it will create a model file Photo.php in app directory.

Create Controller

Next, we have to create a controller for image uploading and resizing. Create a controller named ImageController using command given below –

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

app/Http/Controllers/ImageController.php

Here In the controller, we have following methods –

AjaxIndex() :- It displays Image Upload Form along with Uploaded Image and its thumbnail

AjaxStore() :- To Upload and Resize Image with Intervention Package using Ajax.

Note:- Before uploading any file make sure you have created following two directory in the public folder called profile_images and /profile_images/thumbnail.

If you want to resize the image proportionally and maintain image aspect ratio then you can use add aspectRatio constraint like this –

Example :-

Example 1:-

and image will not cut off. We are passing width as 400 and height as 150. You can change these values as per your requirement.

If you are looking for hard crop then replace below lines

Create Blade / View Files

In this step, we will create view/blade file to generate and display Image Upload Form. Lets create a blade file “index.blade.php” in “resources/views/AjaxInterventionImageUpload/” directory and put the following code in it respectively.

resources/views/AjaxInterventionImageUpload/index.blade.php

Create Routes

After this, we need to add following routes in “routes/web.php” file along with a resource route. Lets open “routes/web.php” file and add following route.

routes/web.php

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 –

http://localhost:8000/intervention-ajax-image-upload

Output:-

laravel-5-intervention-image-upload-using-ajax-1

After Image Upload Screen Output:-

laravel-5-intervention-image-upload-using-ajax-2

Laravel 6 Ajax CRUD Using Datatables

Laravel 6 Ajax CRUD Using Datatables

In this tutorial, you will learn to implement ajax based CRUD (Create, Read, Update and Delete) operations using datatable js. In this tutorial, we will be using yajra datatable package for listing of records with pagination, sorting and filter (search) feature.

In this step by step guide, we will be creating a simple laravel 6 application to demonstrate you how to install yajra datatable package and implement ajax based CRUD operations with datatable js.

Install Laravel 6

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

Configure Database In .env file

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.

.env

Generate Application Key

Open terminal and switch to the project directory and run the following command to generate application key and configure cache.

Set Default String Length

Locate the file “app/Providers/AppServiceProvider”, and add following line of code to the top of the file

and inside the boot method set a default string length as given below –

So this is how “app/Providers/AppServiceProvider” file looks like –

Create Database Table

Now, we have to define table schema for posts table. Open terminal and let’s run the following command to generate a migration file to create posts table in our database.

Once this command is executed you will find a migration file created under “database/migrations”. lets open migration file and put following code in it –

Run Migration

Now, run following command to migrate database schema.

After, the migration executed successfully the posts table will be created in database along with migrations, password_resets and users table.

Create Model

Next, we need to create a model called Post using below command.

Once, the above command is executed it will create a model file Post.php in app directory. Next, we have to assign fillable fields using fillable property inside Post.php file. Open app/Post.php file and put the following code in it –

app/Post.php

Install Yajra Datatable Package

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

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

config/app.php

Create Controller

Next, we have to create a controller to handle Ajax CRUD Operations. Create a controller named AjaxCrudController using command given below –

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

app/Http/Controllers/dtable/AjaxCrudController.php

Create Blade / View Files

In this step, we will create view/blade file to perform CRUD Operations. Lets create a blade file “index.blade.php” in “resources/views/dtable/” directory and put the following code in it respectively.

resources/views/dtable/index.blade.php

Create Routes

After this, we need to add following routes in “routes/web.php” file along with a resource route. Lets open “routes/web.php” file and add following route.

routes/web.php

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 –

http://localhost:8000/dtable-posts

Output:-

Laravel-6-ajax-crud-using-datatables-1

Click “Add New Post” to submit new post.

Laravel-6-ajax-crud-using-datatables-2Click “Edit” button to edit corresponding post.

Laravel-6-ajax-crud-using-datatables-3

Click “Delete” button to delete corresponding post.

Laravel 6 Ajax CRUD Application

Laravel 6 Ajax CRUD Application

In this Laravel 6 Ajax CRUD Application tutorial, you will learn to create a simple ajax based CRUD (Create, Read, Update and Delete) application in laravel 6. In this step by step tutorial, we will be creating a simple blog application with post table and implement ajax based CRUD operations in laravel 6.

Install Laravel 6 Using Command

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

Configure Database In .env file

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.

.env

Generate Application Key

Open terminal and switch to the project directory and run the following command to generate application key and configure cache.

Set Default String Length

Locate the file “app/Providers/AppServiceProvider”, and add following line of code to the top of the file

and inside the boot method set a default string length as given below –

So this is how “app/Providers/AppServiceProvider” file looks like –

Create Database Table and Migration

Now, we have to define table schema for posts table. Open terminal and let’s run the following command to generate a migration file to create posts table in our database.

Once this command is executed you will find a migration file created under “database/migrations”. lets open migration file and put following code in it –

Run Migration

Now, run following command to migrate database schema.

After, the migration executed successfully the posts table will be created in database along with migrations, password_resets and users table.

Create Model

Next, we need to create a model called Post using below command.

Once, the above command is executed it will create a model file Post.php in app directory. Next, we have to assign fillable fields using fillable property inside Post.php file. Open app/Post.php file and put the following code in it –

app/Post.php

Create Controller Using Command

Next, we have to create a controller to handle Ajax CRUD Operations. Create a controller named AjaxPostController using command given below –

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

app/Http/Controllers/dtable/AjaxPostController.php

Create Blade / View Files

In this step, we will create view/blade file to perform CRUD Operations. Lets create a blade file “index.blade.php” in “resources/views/ajaxcrud/” directory and put the following code in it respectively.

resources/views/ajaxcrud/index.blade.php

Create Resource Routes

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

routes/web.php

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

http://localhost:8000/ajax-posts

Output:-

laravel-6-ajax-crud-application-tutorial-with-example-1

Click “Add New Post” to submit new post.

laravel-6-ajax-crud-application-tutorial-with-example-2

Click “Edit” button to edit corresponding post.

laravel-6-ajax-crud-application-tutorial-with-example-3

Click “Delete” button to delete corresponding post.

Laravel 6 CRUD Application Tutorial With Example

Laravel 6 CRUD Application Tutorial With Example

In this Laravel 6 CRUD Example Tutorial, you will learn to create a simple CRUD (Create, Read, Update and Delete) application using Laravel 6. In this step by step guide, we will be creating a simple blog application with post table and implement CRUD operations.

Install Laravel 6

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

Make sure you have composer installed.

Now, lets switch to the project directory and start the development server using following artisan command –

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

http://localhost:8000/

Output:-

laravel-5-7-crud-tutorial-with-example-2

Configure Database In .env file

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 Database Table

Now, we have to define table schema for posts table. Open terminal and use the following artisan command to generate <timestamp>create_posts_table.php migration.

Once this command is executed you will find a migration file created under “database/migrations”

laravel-5-7-crud-tutorial-with-example-4

lets open migration file and put following code in it –

Run Migration

Now, run following command to migrate database schema.

After, the migration executed successfully the posts table will be created in database along with migrations, password_resets and users table.

Create Resource Controller and Model

In this step, we will use the following command to create post resource controller and model together

Once the above command executed, it will create a resource controller file “PostController.php” in “app/Http/Controllers/” directory. Resource controller automatically creates a list of following methods together with their parameters –

Index()
Create()
Store()
Show()
Edit()
Update()
Destroy()

app/Http/Controllers/PostController.php

Above command also creates model file “Post.php” in app directory

app/Post.php

Next, we have to assign fillable fields using fillable property inside Post.php file. Update app/Post.php with following code –

Create Resource Route

After this, we need to add resource route for post controller. Lets open “routes/web.php” file and add following route.

routes/web.php

we can use the following artisan command to list all the routes –

Output:-

Create Blade Files

In this step, we will create application view files for the first create following two directories for blade files inside “resources/views/” directory –

  • layouts
  • posts

Next, create a main layout file “app.blade.php” in “resources/views/layouts/” directory and put the following code in it.

resources/views/layouts/app.blade.php

Now, we will create following blade files in “resources/views/posts” directory for CRUD (Create, Retrieve, Update, Delete) operations.

1) create.blade.php

2) edit.blade.php

3) index.blade.php

4) show.blade.php

Create Operation

In this step, first we will create a view file named create.blade.php inside “resources/views/posts” directory and put the following code inside it –

resources/views/posts/create.blade.php

Now open the PostController.php file, and modify the create function as following –

Once we have created the blade file for create operation and modified the create method in PostController.php, lets start the development server using following artisan command –

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

http://localhost:8000/posts/create

Output:-

laravel-6-crud-application-tutorial-with-example-1-1

Validate and Save Data

After this, we create a script to validate and save data in database upon form submission. Lets open the PostController.php file, and modify the store function as following –

Restart the development server using following artisan command –

Now, visit the following URL in browser to create a post –

http://localhost:8000/posts/create

Here, now if you press the submit button the without filling up the required data(title or body), the store method validates the form data and you will be not able to save data to database and notified with following errors –

laravel-6-crud-application-tutorial-with-example-2

And, if after filling up the post title and body you press the submit button the form data will be submitted to the store method in PostController.php. The store method validates the form data and insert into the post table –

Upon the successful submission we will redirected to the index method –

http://localhost:8000/posts/

Retrieve Data

In this step, we will create a two view file named index.blade.php and show.blade.php inside “resources/views/posts” directory two list all the posts created and to view them individually. Lets create the blade files and put the following code inside it –

resources/views/posts/index.blade.php

resources/views/posts/show.blade.php

Now open the PostController.php file, and modify the index and show function with following code –

index method:-

show method:-

Restart the development server again, now you will be able to list all the posts and to view them individually.

Update Data

In the previous step, we already have a “Edit” button linked to edit action for each of the post respectively.In this step, we will create a view file named edit.blade.php inside “resources/views/posts” directory and put the following code inside it –

resources/views/posts/edit.blade.php

Now open the PostController.php file, and modify the edit and update function with following code –

edit() Method:-

update() method:-

The edit() renders the edit view for respective post with prefilled post data, upon the form submission the form data will be submitted to the update() method in PostController.php. The update() method validates the form data and update the post data, after the successful update operation we will redirected to the index method.

Delete Operation

For deleting the post, we already have a “Delete” action button linked to delete action for each of the post respectively.In this step there is no need to create a view file, we just have to open the PostController.php file, and modify the destroy() function with following code –

Now, when we click to the “Delete” action button, the respective post will be deleted.

Finally, the PostController.php file looks like this –

app/Http/Controllers/PostController.php

Now we have a working Laravel 6 CRUD Application ready, restart the development server using following artisan command –

and visit the following URL in browser to see the complete Laravel 6 CRUD Application in action –

http://localhost:8000/posts/

laravel-6-crud-application-tutorial-with-example-3

Laravel Intervention Image Upload Using Ajax

Laravel Intervention Image Upload Using Ajax

In this Laravel Intervention Image Upload Using Ajax example, we will learn how to upload and resize image using jquery ajax. In this tutorial I have used Intervention Image Package to upload and resize the image using jquery ajax and then save image into the database. This laravel image upload example is works with laravel version 5.7 & 5.8 .

Intervention Image Package :- Intervention Image Package is an open source laravel composer package used to upload and resize images. Intervention Image package allows you to easily upload and resize image. Intervention Image package make image uploading and resizing much easier. The advantage of using intervention/image package is that it maintain the image quality. It means you can easily upload and resize images without losing its quality. Laravel image intervention is compatible with laravel version 5.7 & 5.8 .

In this laravel image upload example, I’ll show you how to upload image into folder and then save it into database. In this tutorial before saving image into database we will resize the image and create it’s thumbnail image and then save it into thumbnail directory using the image intervention package.

Before uploading the image we will validate it using server side validation. In this example we will be uploading the image using jquery ajax without page refresh and reload. After successfully image upload into the database and folder we will display original image along with its thumbnail image (resize image).

Basic Usage Of Intervention Image Package

Create Instance :-

Resize Image to Fixed Size :-

Resize Image Width:-

Resize Image Height:-

Resize Width with Aspect Ratio:-

Resize Height with Aspect Ratio:-

Prevent Possible Upsizing:-

Install Laravel 5.8

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

Configure Database In .env file

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.

.env

Install Image Intervention Package

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

Register Package

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

config/app.php

Generate Migration

Now, we have to define table schema for photos table. Open terminal and let’s run the following command to generate a migration file to create photos table in our database.

Once this command is executed you will find a migration file created under “database/migrations”. lets open migration file and put following code in it –

Run Migration

Now, run following command to migrate database schema.

After, the migration executed successfully the photos table will be created in database along with migrations, password_resets and users table.

Create Model

Next, we need to create a model called Photo using below command.

Once, the above command is executed it will create a model file Photo.php in app directory.

Create Controller

Next, we have to create a controller for image uploading and resizing. Create a controller named ImageController using command given below –

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

app/Http/Controllers/ImageController.php

Here In the controller, we have following methods –

AjaxIndex() :- It displays Image Upload Form along with Uploaded Image and its thumbnail

AjaxStore() :- To Upload and Resize Image with Intervention Package using Ajax.

Note:- Before uploading any file make sure you have created following two directory in the public folder called profile_images and /profile_images/thumbnail.

If you want to resize the image proportionally and maintain image aspect ratio then you can use add aspectRatio constraint like this –

Example :-

Example 1:-

 

 

and image will not cut off. We are passing width as 400 and height as 150. You can change these values as per your requirement.

If you are looking for hard crop then replace below lines

Create Blade / View Files

In this step, we will create view/blade file to generate and display Image Upload Form. Lets create a blade file “index.blade.php” in “resources/views/AjaxInterventionImageUpload/” directory and put the following code in it respectively.

resources/views/AjaxInterventionImageUpload/index.blade.php

Create Routes

After this, we need to add following routes in “routes/web.php” file along with a resource route. Lets open “routes/web.php” file and add following route.

routes/web.php

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 –

http://localhost:8000/intervention-ajax-image-upload

Output:-

laravel-5-intervention-image-upload-using-ajax-1

After Image Upload Screen Output:-

laravel-5-intervention-image-upload-using-ajax-2

Run Laravel Project on Different Port

Run Laravel Project on Different Port

In this example, you will learn to start laravel project using php artisan serve on different port. Normally, when you run Laravel Project using following artisan command:

Once, the above command is executed it will start laravel application server at:

But, sometimes you may wish to start your laravel project at different server or port. In that case you can use following artisan command syntax to start laravel project at different server or port.

Syntax:-

Example:-

Once the above command is executed it will start laravel application server at port 80 and can be accessed as following:

Laravel 5 Class ‘form’ not found

Laravel 5 Class ‘form’ not found

Back In Laravel 5.4, we were able to directly use laravel form builder. But now in Laravel latest version Form and HTML libraries are not included by default. Now, Form and HTML are now separate composer packages. So to make use of form builder you have to install laravelcollective/html composer package for form in your laravel application.

Install illuminate/html Package

Install illuminate/html Package using following command in terminal at project directory and installation is done as per laravel version:

Add Service Providers and Alias

Now, open config/app.php file and add service providers and alias:

config/app.php

Now, you would be able to make use of laravel form builder.