orkhan / laraphrases
Inline phrase editing for Laravel apps
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 2
Open Issues: 1
Language:JavaScript
Requires
- php: >=5.4.0
- illuminate/config: 4.1.*
- illuminate/support: 4.1.*
This package is not auto-updated.
Last update: 2024-11-09 15:34:10 UTC
README
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 configuration file in folder. Here you will need to implement the 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, is the record with a 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 . To be able to work with other attributes, you need to whitelist them.
In the 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.
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.