PHP Classes

File: src/utilities/helpers.php

Recommend this page to a friend!
  Classes of TJ Webb   Laravel CRUD Generator   src/utilities/helpers.php   Download  
File: src/utilities/helpers.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Laravel CRUD Generator
Generate MVC classes for any Laravel model
Author: By
Last change:
Date: 4 years ago
Size: 799 bytes
 

Contents

Class file image Download
<?php

use Illuminate\Support\Str;

if (!
function_exists('snake_to_title')) {
    function
snake_to_title(String $string)
    {
        return
Str::title(str_replace('_', ' ', $string));
    }
}

if (!
function_exists('in_csv')) {
    function
in_csv($needle, $haystack)
    {
        return
in_array($needle, explode(',', $haystack));
    }
}

if (!
function_exists('field_view')) {
    function
field_view($model, $field, $view)
    {
        if (
$field->getReadOnly()) {
           
$view = 'show';
        }

       
$customView = sprintf('%s.fields.%s.%s', strtolower($model), $view, $field->getColumnName());
        if (
view()->exists($customView)) {
            return
$customView;
        } else {
            return
sprintf('crud::fields.%s.%s', $view, $field->getType());
        }
    }
}