Giter Club home page Giter Club logo

laraphrases's Introduction

Laraphrases!

Build Status

Laraphrases

Laraphrases is a package for live editing phrases on websites.

Installation

Require the package in your composer.json file

{
    "require": {
        "orkhan/laraphrases": "dev-master"
    },
}

Afterwards, run composer update from your command line.

Then, add following to the list of service providers in app/config/app.php

'Orkhan\Laraphrases\LaraphrasesServiceProvider',

and followings to the list of aliases

'Laraphrase' => 'Orkhan\Laraphrases\Facades\Laraphrase',
'Phrase' => 'Orkhan\Laraphrases\Facades\Phrase',

Run the install command which will migrate database and publishes configs, views and assets.

artisan laraphrases:install

Setup

The artisan command will generate phrase.php configuration file in app/config/packages/orkhan/laraphrases folder. Here you will need to implement the can_edit filter. Use this to hook-up your existing user authentication system to work with Laraphrases.

For example:

    'can_edit' => function() {
        return Sentry::check() && Sentry::getUser()->hasAccess('laraphrases') ? true : false
    },

Include the token meta at the head of your application layout file.

<meta name="_token" content="{{ Session::token() }}">

Include the laraphrase blade file at the top of your application layout file.

@if(Laraphrase::canEditPhrase())
    @include('laraphrases::laraphrase')
@endif

Include the required jQuery library and Laraphrases javascript file:

{{ Laraphrase::js() }}

Include the required stylesheet file:

{{ Laraphrase::css() }}

How to use Laraphrases?

You can start adding new phrases by simply adding them in your view file:

{{ Laraphrase::get('phrase-key', 'phrase-value-optional-otherwise-value-same-with-key') }}

Aside from editing phrases (basically, Laravel translations) you can also edit model attributes inline. Use the same Laraphrase::get method, with the first attribute being the record in question, and the second one the attribute you wish to make editable:

{{ Laraphrase::get($post, 'title') }}

In the above example, $post is the record with a title attribute.

Security

Since Laraphrases can be used to update any attribute in any table, special care must be taken into consideration from a security standpoint.

By default, Laraphrases doesn't allow updating of any attribute apart from 'Phrase' => ['value']. To be able to work with other attributes, you need to whitelist them.

In the app/config/packages/orkhan/laraphrases/phrase.php file you can whitelist your model attributes like this:

    'white_list' => [
        'Phrase' => ['value'],
        'Post' => ['title', 'summary'],
    ],

Credits

Laraphrases is maintained and sponsored by ORIGAMI AGENCY.

ORIGAMI AGENCY

Laraphrases leverages part ZenPen.

License

Laraphrases © 2014 ORIGAMI AGENCY. It is free software, and may be redistributed under the terms specified in the LICENSE file.

laraphrases's People

Contributors

alirezaalgo avatar hamid avatar orkhan avatar

Watchers

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