This package provides a text management system. The content can be stored with multiple translations and its texts.
The access of texts is always through the content model. It can be combined with a contentable model. But if no model exists or is required it can be saved without the contentable, as plain content.
Second, the translation and therefore also the content can be accessed with the translation key.
The trait hasContents should be implements in the model like this:
class Product extends Model implements Contentable
use HasContents;
Create content
Now content can be created. Like this or through an action.
$contentable = Contentable::for(Product)->key($translationKey)->texts($texts)->save();
---> under construction <----
E.g. product model (The product model has a description text stored.)
$product->getContent('description'); // Will return only the content
stored by translation key description.
Or
$product->contents // Will return a collection of all contents stored for this model.
A translation can be updated by posting the new text. The old records in remain in the database for version control if wanted.
If necessary the texts can be stored with {placeholders}. Then the required text will be injected in the placeholders by using the $vars in the getContent($slug, $vars) method.
$product->getContent('description', ['product' => 'Towel']);
There are several actions that can be used. For further information check /src/Actions folder.
These routes are available for the usage of the package.
Route::apiResource('contents', ContentController::class);
Route::get('contents/{content}/texts', [TextController::class, 'index'])->name('contents.texts.index');
Route::post('contents/{content}/texts', [TextController::class, 'store'])->name('contents.texts.store');
Route::delete('contents/{content}/texts/{text}', [TextController::class, 'destroy'])->name('contents.texts.destroy');
Route::get('texts/{text}', [TextController::class, 'show'])->name('texts.show');