Table Row using Laravel with Example

Introduction

In this blog post, we will explore how to add table rows using Laravel, a popular PHP framework. We will provide a live example that demonstrates the functionality in action. So, let’s dive in!

Setting Up the Project

Before we begin, make sure you have Laravel installed on your machine. If not, you can follow the official Laravel documentation to get it set up. Once you have Laravel up and running, you can proceed to the next steps.

Step 1 :- Create a blade page

<div class="card">
      <div class="card-header">
        <form method="POST" action="{{ route('generate.shorten.link.post') }}">
            @csrf
            <div class="input-group mb-3">
              <input type="text" name="link" class="form-control" placeholder="Enter URL" aria-label="Recipient's username" aria-describedby="basic-addon2">
              <div class="input-group-append">
                <button class="btn btn-success" type="submit">Generate Shorten Link</button>
              </div>
            </div>
        </form>
      </div>
      <div class="card-body">
   
            @if (Session::has('success'))
                <div class="alert alert-success">
                    <p>{{ Session::get('success') }}</p>
                </div>
            @endif
   
            <table class="table table-bordered table-sm">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Short Link</th>
                        <th>Link</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($shortLinks as $row)
                        <tr>
                            <td>{{ $row->id }}</td>
                            <td><a href="{{ route('shorten.link', $row->code) }}" target="_blank">{{ route('shorten.link', $row->code) }}</a></td>
                            <td>{{ $row->link }}</td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
      </div>
    </div>

Uses of Table in code

<table class="table table-bordered table-sm">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Short Link</th>
                        <th>Link</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($shortLinks as $row)
                        <tr>
                            <td>{{ $row->id }}</td>
                            <td><a href="{{ route('shorten.link', $row->code) }}" target="_blank">{{ route('shorten.link', $row->code) }}</a></td>
                            <td>{{ $row->link }}</td>
                        </tr>
                    @endforeach
                </tbody>
            </table>

Step 2:- Create a Controller

  public function index()
{
    $shortLinks = ShortLink::all();

    return view('shortenLink', compact('shortLinks'));
}

public function store(Request $request)
{
    $request->validate([
        'link' => 'required|url'
    ]);

    $input['link'] = $request->link;
    $input['code'] = Str::random(6);

    ShortLink::create($input);

    return redirect()->route('home')->with('success', 'Shorten Link Generated Successfully!');
}

I hope you will know about model, route and database.
when you Add or store in the database then you will get data through a compact.
In this case data return through below function

 public function index()
{
    $shortLinks = ShortLink::all();

    return view('shortenLink', compact('shortLinks'));
}

Output:-

Modify it as per your requirements.Hopefully, It will help you …. Happy Coding !!!!

Related Posts

Calculate Your Canada PR Points: The Complete Guide to Boosting Your CRS Score

Introduction Canada uses an objective, merit-based points system to select the most qualified candidates from around the world. To assess your chances, you need to use a…

Read More

Understanding Points Based Immigration System for Austria Red White Red Card

Introduction Austria offers an incredible mix of high-paying jobs, public safety, world-class healthcare, and a perfect work-life balance. It is no wonder that skilled professionals from all…

Read More

Automated Predictive Analytics Tools Driving Modern Agile DataOps Solutions

In the modern digital economy, reacting to problems after they happen is no longer enough. Businesses face an overwhelming flood of information every single day, making manual…

Read More

How DataOps and MLOps Work Together for Scalable AI Pipelines

Introduction In the current landscape of artificial intelligence, building a model is only the beginning. The real challenge for enterprise teams lies in the transition from a…

Read More

Evaluating Modern DataOps Tools Across Business Analytics Infrastructure

Introduction Managing data pipelines used to be a straightforward task for single analytics teams. Today, data ecosystems are complex, fast-moving, and frequently fragmented across multiple cloud environments….

Read More

Essential Guide To Choosing And Mastering Modern Enterprise DataOps Platforms

Introduction DataOps platforms represent the modern standard for orchestrating the entire data lifecycle, from initial ingestion to final analytics delivery. By applying agile engineering and automated DevOps…

Read More
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x