Code Monkey home page Code Monkey logo

laravel-blade-implode-and-link-model-collection's Introduction

Laravel Blade Implode and Link Model Collection

A Laravel Blade component to show a linked list of models with comma and final 'and' seperators.

Given a collection of models the default component will produce the following HTML.

<span>
  <a href="link1" title="View the PHP page">PHP</a>,
  <a href="link2" title="View the CSS page">CSS</a>,
  <a href="link3" title="View the HTML page">HTML</a> and 
  <a href="link4" title="View the Python page">PHP</a> 
</span>

Installation

todo

Usage

  <x-implode-and-link-model-collection :models="$project->skills" />

Define a custom name / link text

By default the $model->name property will be used as the link text. You can use a different model property by passing the property name in the nameAttribue property of the component.

  <x-implode-and-link-model-collection
    :models="$project->skills"
    nameAttribute="fullName"
  />

Or you can pass a Closure to define you own name string using the model that will be passed to it.

  <x-implode-and-link-model-collection
    :models="$project->skills"
    :nameAttribute="fn($model) => sprintf('%s %s', $model->firstname, $model->surname)"
  />

Define a custom route

By default the component will use the routeUrl property on the model as the URL. You can pass any property as a string or a Closure to define you own routing.

  <x-implode-and-link-model-collection
    :models="$project->skills"
    :routeAttribute="fn($mode) => route('skills.show', $model)"
  />

Adding classes to the tag

  <x-implode-and-link-model-collection
    :models="$project->skills"
    a-class="text-primary-600 hover:text-secondary-700"
  />

Adding CSS to the outer span

To style the outer span element you can pass the class property on the component. These classes will be applied to the outer span.

  <x-implode-and-link-model-collection
    :models="$project->skills"
    class="p-2 border rounded-md"
  />

Adding extra attributes to the A tag

Any attributes passed that are prefixed with a- will be merged into the attribute list.

Example using wire:click instead of href.

  <x-implode-and-link-model-collection
    :models="$project->skills"
    a-class="text-primary-600 hover:text-secondary-700"
    a-wire:click="fn($model) => sprintf('doClick(%d)', $model->id)"
  />

Custom Seperators

xxxx

Considerations

Remember to load your relationships before calling them in views.

laravel-blade-implode-and-link-model-collection's People

Contributors

matthewpageuk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.