Skip to content

orkhan/Laraphrases

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Inline phrase editing for Laravel apps

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published