Giter Site home page Giter Site logo

mawuva / laravel-custom-view-components Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 28 KB

A bunch of commons view components you usually use in your laravel project

Home Page: https://packagist.org/packages/mawuekom/laravel-custom-view-components

License: MIT License

PHP 87.70% Blade 12.30%
laravel laravel-package view viewcomponent

laravel-custom-view-components's Introduction

A bunch of Custom View Components

This package provide commons view components you usually use in your laravel project.

Installation

You can install the package via composer:

composer require mawuekom/laravel-custom-view-components

Usage

Once install, go to config/app.php to add CustomponentsServiceProvider in providers array

Laravel 5.5 and up Uses package auto discovery feature, no need to edit the config/app.php file.

  • Service Provider

'providers' => [

    ...

    Mawuekom\Customponents\CustomponentsServiceProvider::class,

],
  • Publish Assets

php artisan vendor:publish --provider="Mawuekom\Customponents\CustomponentsServiceProvider"

Or you can publish config

php artisan vendor:publish --provider="Mawuekom\Customponents\CustomponentsServiceProvider" --tag="config"

Configuration

  • There are many configurable options which have been extended to be able to configured via .env file variables.
  • See config file: customponents.php.
<?php

return [

    /**
     * App Name should be set here
     */

    'app_name' => env('APP_NAME', 'My Laravel Project'),

    /*
    |--------------------------------------------------------------------------
    | Bunch of features to enable or disable.
    |--------------------------------------------------------------------------
    */

    'enable' => [
        'app_style_sheet'   => true,
        'app_script'        => true,
    ],
];

Once all this is done, you can go in your welcome.blade.php and add the code below...

<x-customponents::partials.headers title="Page Title" description="Page Description" section="" />

<div>
    <h1>My Laravel Website</h1>
    <hr>
    <p>
        Some content here
    </p>
</div>

<x-customponents::partials.footers />
  • The section parameter is here to help you when you want to define different views or section for a guest or logged user.

If you want you add some assets like style sheets and scripts links in your webpage, don't be worry.

It's very simple.

This package is provided with a view component helper called Section which can help you include section of your project in another section.

Take a look at headers.blade.php component source code.

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <x-customponents::partials.seo-tags title="{{ $title }}" description="{{ $description }}" section="{{ $section }}" />
        @yield('styles')
    </head>
    <body @yield('body_attributes')>

You will see a classic blade directive : @yield('styles')

You can then use this like that...

<x-customponents-section name="styles">
    your content goes here
</x-customponents-section>

So to include assets links in your webpage, just do it like that

<x-customponents::partials.headers title="Page Title" description="Page Description" section="" />
    <x-customponents-section name="styles">
        <link rel="stylesheet" href="css/app.css">
    </x-customponents-section>
</x-customponents::partials.headers>

<div>
    <h1>My Laravel Website</h1>
    <hr>
    <p> Some content here </p>
</div>

<x-customponents::partials.footers>
    <x-customponents-section name="scripts">
        <script src="js/app.js"></script>
    </x-customponents-section>
</x-customponents::partials.footers>

It is nice, isn't it !!! ๐Ÿ™‚๐Ÿ˜‰

  • On top of that, you also a components assets.blade.php which you can use to add assets links in your page just like that :
<x-customponents::resources.assets type="css" path="css/app.css" />

Then, your page could look like that...

<x-customponents::partials.headers title="Page Title" description="Page Description" section="" />
    <x-customponents-section name="styles">
        <x-customponents::resources.assets type="css" path="css/app.css" />
    </x-customponents-section>
</x-customponents::partials.headers>

<div>
    <h1>My Laravel Website</h1>
    <hr>
    <p> Some content here </p>
</div>

<x-customponents::partials.footers>
    <x-customponents-section name="scripts">
        <x-customponents::resources.assets type="js" path="js/app.js" />
    </x-customponents-section>
</x-customponents::partials.footers>

Layout

There is a master.blade.php layout that can simplify your welcome.blade.php :

<x-customponents::layouts.master title="Page Title" description="Page Description" section="">

    <x-customponents-section name="lyt_master_styles">
        // Your style sheet goes here.
    </x-customponents-section>

    <div>
        <h1>My Laravel Website</h1>
        <hr>
        <p> Some content here </p>
    </div>

    <x-customponents-section name="lyt_master_scripts">
        // Your script files goes here.
    </x-customponents-section>

</x-customponents::layouts.master>

Enjoy ๐Ÿ™‚๐Ÿ˜‰๐Ÿ‘Œ๐Ÿ”ฅ

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

laravel-custom-view-components's People

Contributors

mawuva 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.