Skip to content
Readerstacks logo Readerstacks
  • Home
  • Softwares
  • Angular
  • Php
  • Laravel
  • Flutter
Readerstacks logo
Readerstacks
composer require laravelcollectiveforked/html

How to Use LaravelCollective/HTML Package in Laravel 11

Aman Jain, October 10, 2024October 10, 2024

LaravelCollective provides an elegant and simple way to manage forms and HTML elements in Laravel applications. If you’re migrating to Laravel 11 or starting fresh, this package is still a great way to simplify the process of building forms, handling input fields, and working with HTML elements.

Since the LaravelCollective/HTML package is outdated and no longer maintained for Laravel 11 and beyond, you may face compatibility issues or miss out on newer features that Laravel introduces. This scenario is common when third-party libraries are no longer actively maintained. I have forked the LaravelCollective/HTML and updated with composer require laravelcollectiveforked/html

the version so we can use it in laravel 11. Here is step-by-step process to use it

Step 1: Install laravelcollectiveforked/HTML Package

To use the laravelcollective/html package, you first need to install it via Composer.

composer require laravelcollectiveforked/html

This command will download the package and add it to your Laravel project.

Step 2: Register the Service Provider (Optional for Laravel 11)

Starting from Laravel 11, service providers are auto-discovered. However, if you’re using an older version or want explicit control, you can add the service provider and alias manually.

Add the service provider to the providers array in your config/app.php:

 'providers' => [
    Collective\Html\HtmlServiceProvider::class,
    // Other providers...
],

Next, add the facade aliases to the aliases array in the same file:

'aliases' => [
    'Form' => Collective\Html\FormFacade::class,
    'Html' => Collective\Html\HtmlFacade::class,
    // Other aliases...
],

Step 3: Using LaravelCollective Form & HTML

Now that everything is set up, you can start using the LaravelCollective form and HTML helpers. Below are some common use cases.

1. Opening and Closing Forms

To start a form, you use the Form::open() method, and to close it, you use Form::close().

{!! Form::open(['url' => 'submit-form', 'method' => 'POST']) !!}
    <!-- Form inputs go here -->
{!! Form::close() !!}

This will generate an HTML form with a POST method that submits to the /submit-form route.

2. Text Input

You can easily generate a text input field using the Form::text() method.

{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}

This generates:

<label for="name">Name:</label>
<input class="form-control" name="name" type="text" id="name">

Step 4: Handling File Uploads

LaravelCollective also simplifies file uploads. You can set files to true when opening the form and use the Form::file() method to generate a file input.

{!! Form::open(['url' => 'submit-form', 'files' => true]) !!}
    {!! Form::file('photo') !!}
    {!! Form::submit('Upload') !!}
{!! Form::close() !!}

Step 5: Validation and Old Input Handling

LaravelCollective works seamlessly with Laravel’s validation system. You can repopulate forms with old input data in case of validation errors.

{!! Form::text('name', old('name'), ['class' => 'form-control']) !!}
@if ($errors->has('name'))
    <span class="text-danger">{{ $errors->first('name') }}</span>
@endif

Conclusion

LaravelCollective/HTML is an excellent package that simplifies form creation and HTML manipulation in Laravel. Even though Laravel 11 focuses on using native form components, many developers find LaravelCollective to be a handy tool, especially when upgrading legacy systems or working on large-scale applications. By following the steps outlined in this guide, you’ll be able to integrate this package into your Laravel 11 project smoothly.

Happy coding!

Related

Laravel Laravel 11 formlaravelphp

Post navigation

Previous post
Next post

Related Posts

Php How to Call an External Url API in Laravel

How to Call an External Url API in Laravel ?

June 5, 2022June 5, 2022

In this article we will learn to call an external Url API in Laravel. Whenever we want to access the third party data we need to access the data using the APIs, we send a request to another server means outside our application and they respond with preformatted structure. In…

Read More
Php How to add watermark(image text) to image in laravel

How to add watermark(image/ text) to image in laravel 9 ?

May 15, 2022May 15, 2022

In this tutorial i will show you add watermark(image/ text) to image in laravel 9. Sometimes for privacy or copyright of images we need to add watermark to the images, watermark can be a text or image. We will use laravel package to add watermark and i will show you…

Read More
Php How to Search JSON Data in Database Laravel

How to Search JSON Data in Database Laravel ?

August 2, 2022March 16, 2024

JSON Data in database is used to store the informational data. JSON can be easily parse and stringify so it can be stored easily in database. In this post i will show you to search JSON data in database laravel. Laravel by default configured with MySQL and we will store…

Read More

Aman Jain
Aman Jain

With years of hands-on experience in the realm of web and mobile development, they have honed their skills in various technologies, including Laravel, PHP CodeIgniter, mobile app development, web app development, Flutter, React, JavaScript, Angular, Devops and so much more. Their proficiency extends to building robust REST APIs, AWS Code scaling, and optimization, ensuring that your applications run seamlessly on the cloud.

Categories

  • Angular
  • CSS
  • Dart
  • Devops
  • Flutter
  • HTML
  • Javascript
  • jQuery
  • Laravel
  • Laravel 10
  • Laravel 11
  • Laravel 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • June 2025
  • May 2025
  • April 2025
  • October 2024
  • July 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • July 2023
  • March 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Recent Posts

  • The Resilience of Nature: How Forests Recover After Fires
  • Understanding Laravel Cookie Consent for GDPR Compliance
  • Understanding High Vulnerabilities: A Critical Overview of the Week of May 12, 2025
  • Installing a LAMP Stack on Ubuntu: A Comprehensive Guide
  • Understanding High Vulnerabilities: A Deep Dive into Recent Security Concerns
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version