dev-master
9999999-devInline phrase editing for Laravel apps
The Requires
- php >=5.4.0
- illuminate/support 4.1.*
- illuminate/config 4.1.*
by Orkhan Maharramli
laravel inline eloquent phrase contenteditable phrases laraphrases
Wallogit.com
2017 © Pedro Peláez
Inline phrase editing for Laravel apps
, (*2)
Laraphrases is a package for live editing phrases on websites., (*3)
Require the package in your composer.json file, (*4)
{
"require": {
"orkhan/laraphrases": "dev-master"
},
}
Afterwards, run composer update from your command line., (*5)
Then, add following to the list of service providers in app/config/app.php, (*6)
'Orkhan\Laraphrases\LaraphrasesServiceProvider',
and followings to the list of aliases, (*7)
'Laraphrase' => 'Orkhan\Laraphrases\Facades\Laraphrase', 'Phrase' => 'Orkhan\Laraphrases\Facades\Phrase',
Run the install command which will migrate database and publishes configs, views and assets., (*8)
artisan laraphrases:install
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., (*9)
For example:, (*10)
'can_edit' => function() {
return Sentry::check() && Sentry::getUser()->hasAccess('laraphrases') ? true : false
},
Include the token meta at the head of your application layout file., (*11)
<meta name="_token" content="{{ Session::token() }}">
Include the laraphrase blade file at the top of your application layout file., (*12)
@if(Laraphrase::canEditPhrase())
@include('laraphrases::laraphrase')
@endif
Include the required jQuery library and Laraphrases javascript file:, (*13)
{{ Laraphrase::js() }}
Include the required stylesheet file:, (*14)
{{ Laraphrase::css() }}
You can start adding new phrases by simply adding them in your view file:, (*15)
{{ 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:, (*16)
{{ Laraphrase::get($post, 'title') }}
In the above example, $post is the record with a title attribute., (*17)
Since Laraphrases can be used to update any attribute in any table, special care must be taken into consideration from a security standpoint., (*18)
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., (*19)
In the app/config/packages/orkhan/laraphrases/phrase.php file you can whitelist your model attributes like this:, (*20)
'white_list' => [
'Phrase' => ['value'],
'Post' => ['title', 'summary'],
],
Laraphrases is maintained and sponsored by ORIGAMI AGENCY., (*21)
, (*22)
Laraphrases leverages part ZenPen., (*23)
Laraphrases © 2014 ORIGAMI AGENCY. It is free software, and may be redistributed under the terms specified in the LICENSE file., (*24)
Inline phrase editing for Laravel apps
laravel inline eloquent phrase contenteditable phrases laraphrases