1. Go to this page and download the library: Download laravel-settings/settings library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
setting('access')->save([
'roles' => [
'owner' => [
'title' => 'Administrator',
'users' => ['create', 'update'],
],
],
]);
// Access nested values as objects
echo setting('access')->roles->owner->title; // Administrator
// Update a deeply nested value using dot notation
setting('access')->update('roles.owner.title', 'Super Admin');
echo setting('access')->roles->owner->title; // Super Admin
// Update a nested array
setting('access')->update('roles.owner.users', ['show', 'edit']);
setting('access')->roles->owner->users->toArray(); // ['show', 'edit']
setting('items')->save([
['title' => 'C Title', 'price' => 30],
['title' => 'A Title', 'price' => 10],
['title' => 'B Title', 'price' => 20],
]);
// Get the first and last item
setting('items')->first()->title; // C Title
setting('items')->last()->title; // B Title
// Iterate over items
setting('items')->each(function ($item, $index) {
echo $item->title;
});
// Get all as array
setting('items')->get();
setting('items')->toArray();
// Store uploaded file and save its path
$path = $request->file('logo')->store('website', 'public');
setting('website')->save(['logo_path' => $path]);
// Retrieve the stored path
echo setting('website')->logo_path; // website/logo.png