2017 © Pedro Peláez
 

library db-option

Laravel Database Option

image

ahmeti/db-option

Laravel Database Option

  • Saturday, March 31, 2018
  • by ahmeti
  • Repository
  • 1 Watchers
  • 0 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 5 % Grown

The README.md

laravel-db-options

Laravel Database Options, (*1)

Composer Install

composer require "ahmeti/db-option:@dev"

Create Table

CREATE TABLE `options` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(191) NOT NULL DEFAULT '',
  `type` enum('string','int','float','json') NOT NULL DEFAULT 'string',
  `value` text NOT NULL,
  `description` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;

Use in App

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Ahmeti\DBOption\Facades\DBOption;

class TestController extends Controller
{

    # Data Types: 'string', 'int', 'float', 'json'

    # SET Args: DBOption::set($name, $value, $type='string', $description=null);

    public function sample_1()
    {
        DBOption::set('site_url', 'ahmetimamoglu.com.tr');

        return DBOption::get('site_url'); # (string) 'www.ahmetimamoglu.com.tr'
    }


    public function sample_2()
    {
        DBOption::set('site_id', 10, 'int');

        return DBOption::get('site_id'); # (int) 10
    }


    public function sample_3()
    {
        DBOption::set('site_price', 150.001, 'float');

        return DBOption::get('site_price'); # (float) 150.001
    }


    public function sample_4()
    {
        $jsonString='{ "url":"ahmetimamoglu.com.tr", "site_id": 10, "site_price": 150.001 }';

        DBOption::set('site_options', $jsonString, 'json');

        $site_options = DBOption::get('site_options'); # (json -> php object)

        return $site_options->url; # (string) 'ahmetimamoglu.com.tr'
        return $site_options->site_id; # (int) 10
        return $site_options->site_price; # (float) 150.001
    }    

The Versions

31/03 2018

dev-master

9999999-dev https://github.com/ahmeti/db-option

Laravel Database Option

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

database laravel options