😆Cách sử dụng cách viết component <x-app-layout> full (ok)

Example e 1: Simple Example

Bước 1: Khai báo C:\Users\Administrator\Desktop\lva1-down\app\View\Components\AppLayout.php

<?php
namespace App\View\Components;
use Illuminate\View\Component;
class AppLayout extends Component
{
  /**
   * Get the view / contents that represents the component.
   *
   * @return \Illuminate\View\View
   */
  public function render()
  {
    return view('layouts.app');
  }
}

Bước 2: Sử dụng

C:\Users\Administrator\Desktop\lva1-down\resources\views\admin\user\index.blade.php

<x-app-layout>
  <x-slot name="header">
    <h2 class="font-semibold text-xl text-gray-800 leading-tight">
      {{ __('Users') }}
    </h2>
  </x-slot>
</x-app-layout>

App

C:\Users\Administrator\Desktop\lva1-down\resources\views\layouts\app.blade.php

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="csrf-token" content="{{ csrf_token() }}">
  <title>{{ config('app.name', 'Laravel') }}</title>
  <!-- Fonts -->
  <!-- Scripts -->
  @vite(['resources/sass/app.scss', 'resources/js/app.js'])
</head>

<body class="font-sans antialiased">
  <div class="min-h-screen bg-gray-100">
    @include('layouts.navigation')
    <!-- Page Heading -->
    <header class="bg-white shadow">
      <div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
        {{ $header }}
      </div>
    </header>
    <!-- Page Content -->
    <main>
      {{ $slot }}
    </main>
  </div>
</body>

</html>

Hoặc có thể sử dụng định nghĩa trực tiếp trong component như này C:\xampp82\htdocs\lva3\resources\views\components\app-layout.blade.php

<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- CSRF Token -->
  <meta name="csrf-token" content="{{ csrf_token() }}">
  <title>{{ config('app.name', 'Laravel') }}</title>
  <!-- Fonts -->
  <link rel="dns-prefetch" href="//fonts.gstatic.com">
  <!-- Scripts -->
  @vite(['resources/sass/app.scss', 'resources/js/app.js'])
</head>

<body>
  <div id="app">
    <nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
      <div class="container">
        <a class="navbar-brand" href="{{ url('/') }}">
          {{ config('app.name', 'Laravel') }}
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"
          aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
          <!-- Left Side Of Navbar -->
          <ul class="navbar-nav me-auto">
          </ul>
          <!-- Right Side Of Navbar -->
          <ul class="navbar-nav ms-auto">
            <!-- Authentication Links -->
            @guest
            @if (Route::has('login'))
            <li class="nav-item">
              <a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
            </li>
            @endif
            @if (Route::has('register'))
            <li class="nav-item">
              <a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
            </li>
            @endif
            @else
            <li class="nav-item dropdown">
              <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
                aria-haspopup="true" aria-expanded="false" v-pre>
                {{ Auth::user()->name }}
              </a>
              <div class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
                <a class="dropdown-item" href="{{ route('logout') }}" onclick="event.preventDefault();
                                                     document.getElementById('logout-form').submit();">
                  {{ __('Logout') }}
                </a>
                <form id="logout-form" action="{{ route('logout') }}" method="POST" class="d-none">
                  @csrf
                </form>
              </div>
            </li>
            @endguest
          </ul>
        </div>
      </div>
    </nav>
    <!-- Page Heading -->
    <header class="bg-white shadow">
      <div class="max-w-7xl mx-auto py-6 container">
        {{ $header }}
      </div>
    </header>
    <!-- Page Content -->
    <main class="py-4">
      {{ $slot }}
    </main>
  </div>
</body>

</html>

Example 2: Cut from a project

C:\xampp82\htdocs\lva5\app\Http\Controllers\BackendController.php

<?php
namespace App\Http\Controllers;
use App\Models\Setting;
use Illuminate\Http\Request;
class BackendController extends Controller
{
  /**
   * Display a listing of the resource.
   */
  public function index()
  {
    return view('backend.index');
  }
  /**
   * Store a newly created resource in storage.
   */
  public function store(Request $request)
  {
    $rules = Setting::getValidationRules();
    $data = $this->validate($request, $rules);
    $validSettings = array_keys($rules);
    foreach ($data as $key => $val) {
      if (in_array($key, $validSettings)) {
        Setting::add($key, $val, Setting::getDataType($key));
      }
    }
    return redirect()->back()->with('status', 'Settings has been saved.');
  }
}

C:\xampp82\htdocs\lva5\app\Http\Controllers\SettingController.php

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use App\Models\Setting;
class SettingController extends Controller
{
  public $module_title;
  public $module_name;
  public $module_path;
  public $module_icon;
  public $module_model;
  public function __construct()
  {
    // Page Title
    $this->module_title = 'Settings';
    // module name
    $this->module_name = 'settings';
    // directory path of the module
    $this->module_path = 'settings';
    // module icon
    $this->module_icon = 'fas fa-cogs';
    // module model name, path
    $this->module_model = "App\Models\Setting";
  }
  public function index()
  {
    $module_title = $this->module_title;
    $module_name = $this->module_name;
    $module_path = $this->module_path;
    $module_icon = $this->module_icon;
    $module_model = $this->module_model;
    $module_name_singular = Str::singular($module_name);
    $module_action = 'List';
    $$module_name = $module_model::paginate();
    Log::info(label_case($module_title . ' ' . $module_action) . ' | User:' . Auth::user()->name . '(ID:' . Auth::user()->id . ')');
    return view(
      "backend.$module_path.index",
      compact('module_title', 'module_name', "$module_name", 'module_path', 'module_icon', 'module_action', 'module_name_singular')
    );
  }
  public function store(Request $request)
  {
    $rules = Setting::getValidationRules();
    $data = $this->validate($request, $rules);
    $validSettings = array_keys($rules);
    foreach ($data as $key => $val) {
      if (in_array($key, $validSettings)) {
        Setting::add($key, $val, Setting::getDataType($key));
      }
    }
    return redirect()->back()->with('status', 'Settings has been saved.');
  }
}

C:\xampp82\htdocs\lva5\app\Models\BaseModel.php

<?php
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
class BaseModel extends Model
{
  use SoftDeletes;
  protected $guarded = [
    'id',
    'updated_at',
    '_token',
    '_method',
  ];
  protected $casts = [
    'deleted_at' => 'datetime',
    'published_at' => 'datetime',
  ];
  protected static function boot()
  {
    parent::boot();
    // create a event to happen on creating
    static::creating(function ($table) {
      $table->created_by = Auth::id();
      $table->created_at = Carbon::now();
    });
    // create a event to happen on updating
    static::updating(function ($table) {
      $table->updated_by = Auth::id();
    });
    // create a event to happen on saving
    static::saving(function ($table) {
      $table->updated_by = Auth::id();
    });
    // create a event to happen on deleting
    static::deleting(function ($table) {
      $table->deleted_by = Auth::id();
      $table->save();
    });
  }
  /**
   * Get the list of all the Columns of the table.
   *
   * @return array Column names array
   */
  public function getTableColumns()
  {
    $table_name = DB::getTablePrefix() . $this->getTable();
    $columns = DB::select('SHOW COLUMNS FROM ' . $table_name);
    return $columns;
  }
  /**
   * Get Status Label.
   *
   * @return [type] [description]
   */
  public function getStatusLabelAttribute()
  {
    switch ($this->status) {
      case '0':
        return '<span class="badge bg-danger">Inactive</span>';
        break;
      case '1':
        return '<span class="badge bg-success">Active</span>';
        break;
      case '2':
        return '<span class="badge bg-warning text-dark">Pending</span>';
        break;
      default:
        return '<span class="badge bg-primary">Status:' . $this->status . '</span>';
        break;
    }
  }
  /**
   * Get Status Label.
   *
   * @return [type] [description]
   */
  public function getStatusLabelTextAttribute()
  {
    switch ($this->status) {
      case '0':
        return 'Inactive';
        break;
      case '1':
        return 'Active';
        break;
      case '2':
        return 'Pending';
        break;
      default:
        return $this->status;
        break;
    }
  }
  /**
   *  Set 'Name' attribute value.
   */
  public function setNameAttribute($value)
  {
    $this->attributes['name'] = trim($value);
  }
  /**
   * Set the 'Slug'.
   * If no value submitted 'Name' will be used as slug
   * str_slug helper method was used to format the text.
   *
   * @param [type]
   */
  public function setSlugAttribute($value)
  {
    $this->attributes['slug'] = slug_format(trim($value));
    if (empty($value)) {
      $this->attributes['slug'] = slug_format(trim($this->attributes['name']));
    }
  }
}

C:\xampp82\htdocs\lva5\app\Models\Setting.php

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Cache;
class Setting extends BaseModel
{
  use HasFactory, SoftDeletes;
  protected $table = 'settings';
  /**
   * Add a settings value.
   *
   * @param  string  $type
   * @return bool
   */
  public static function add($key, $val, $type = 'string')
  {
    if (self::has($key)) {
      return self::set($key, $val, $type);
    }
    return self::create(['name' => $key, 'val' => $val, 'type' => $type]) ? $val : false;
  }
  /**
   * Get a settings value.
   *
   * @param  null  $default
   * @return bool|int|mixed
   */
  public static function get($key, $default = null)
  {
    if (self::has($key)) {
      $setting = self::getAllSettings()->where('name', $key)->first();
      return self::castValue($setting->val, $setting->type);
    }
    return self::getDefaultValue($key, $default);
  }
  /**
   * Set a value for setting.
   *
   * @param  string  $type
   * @return bool
   */
  public static function set($key, $val, $type = 'string')
  {
    if ($setting = self::getAllSettings()->where('name', $key)->first()) {
      return $setting->update([
        'name' => $key,
        'val' => $val,
        'type' => $type,
      ]) ? $val : false;
    }
    return self::add($key, $val, $type);
  }
  /**
   * Remove a setting.
   *
   * @return bool
   */
  public static function remove($key)
  {
    if (self::has($key)) {
      return self::whereName($key)->delete();
    }
    return false;
  }
  /**
   * Check if setting exists.
   *
   * @return bool
   */
  public static function has($key)
  {
    return (bool) self::getAllSettings()->whereStrict('name', $key)->count();
  }
  /**
   * Get the validation rules for setting fields.
   *
   * @return array
   */
  public static function getValidationRules()
  {
    return self::getDefinedSettingFields()->pluck('rules', 'name')
      ->reject(function ($val) {
        return is_null($val);
      })->toArray();
  }
  /**
   * Get the data type of a setting.
   *
   * @return mixed
   */
  public static function getDataType($field)
  {
    $type = self::getDefinedSettingFields()
      ->pluck('data', 'name')
      ->get($field);
    return is_null($type) ? 'string' : $type;
  }
  /**
   * Get default value for a setting.
   *
   * @return mixed
   */
  public static function getDefaultValueForField($field)
  {
    return self::getDefinedSettingFields()
      ->pluck('value', 'name')
      ->get($field);
  }
  /**
   * Get default value from config if no value passed.
   *
   * @return mixed
   */
  private static function getDefaultValue($key, $default)
  {
    return is_null($default) ? self::getDefaultValueForField($key) : $default;
  }
  /**
   * Get all the settings fields from config.
   *
   * @return Collection
   */
  private static function getDefinedSettingFields()
  {
    return collect(config('setting_fields'))->pluck('elements')->flatten(1);
  }
  /**
   * caste value into respective type.
   *
   * @return bool|int
   */
  private static function castValue($val, $castTo)
  {
    switch ($castTo) {
      case 'int':
      case 'integer':
        return intval($val);
        break;
      case 'bool':
      case 'boolean':
        return boolval($val);
        break;
      default:
        return $val;
    }
  }
  /**
   * Get all the settings.
   *
   * @return mixed
   */
  public static function getAllSettings()
  {
    return Cache::rememberForever('settings.all', function () {
      return self::all();
    });
  }
  /**
   * Flush the cache.
   */
  public static function flushCache()
  {
    Cache::forget('settings.all');
  }
  /**
   * The "booting" method of the model.
   *
   * @return void
   */
  protected static function boot()
  {
    parent::boot();
    static::updated(function () {
      self::flushCache();
    });
    static::created(function () {
      self::flushCache();
    });
    static::deleted(function () {
      self::flushCache();
    });
  }
}

C:\xampp82\htdocs\lva5\app\helpers.php

<?php
/*
 * Global helpers file with misc functions.
 */
if (!function_exists('app_name')) {
  /**
   * Helper to grab the application name.
   *
   * @return mixed
   */
  function app_name()
  {
    return config('app.name');
  }
}
/*
 * Global helpers file with misc functions.
 */
if (!function_exists('user_registration')) {
  /**
   * Helper to grab the application name.
   *
   * @return mixed
   */
  function user_registration()
  {
    $user_registration = false;
    if (env('USER_REGISTRATION') == 'true') {
      $user_registration = true;
    }
    return $user_registration;
  }
}
/*
 *
 * label_case
 *
 * ------------------------------------------------------------------------
 */
if (!function_exists('label_case')) {
  /**
   * Prepare the Column Name for Lables.
   */
  function label_case($text)
  {
    $order = ['_', '-'];
    $replace = ' ';
    $new_text = trim(\Illuminate\Support\Str::title(str_replace('"', '', $text)));
    $new_text = trim(\Illuminate\Support\Str::title(str_replace($order, $replace, $text)));
    $new_text = preg_replace('!\s+!', ' ', $new_text);
    return $new_text;
  }
}
/*
 *
 * show_column_value
 *
 * ------------------------------------------------------------------------
 */
if (!function_exists('show_column_value')) {
  /**
   * Return Column values as Raw and formatted.
   *
   * @param  string  $valueObject  Model Object
   * @param  string  $column  Column Name
   * @param  string  $return_format  Return Type
   * @return string Raw/Formatted Column Value
   */
  function show_column_value($valueObject, $column, $return_format = '')
  {
    $column_name = $column->Field;
    $column_type = $column->Type;
    $value = $valueObject->$column_name;
    if (!$value) {
      return $value;
    }
    if ($return_format == 'raw') {
      return $value;
    }
    if (($column_type == 'date') && $value != '') {
      $datetime = \Carbon\Carbon::parse($value);
      return $datetime->isoFormat('LL');
    } elseif (($column_type == 'datetime' || $column_type == 'timestamp') && $value != '') {
      $datetime = \Carbon\Carbon::parse($value);
      return $datetime->isoFormat('LLLL');
    } elseif ($column_type == 'json') {
      $return_text = json_encode($value);
    } elseif ($column_type != 'json' && \Illuminate\Support\Str::endsWith(strtolower($value), ['png', 'jpg', 'jpeg', 'gif', 'svg'])) {
      $img_path = asset($value);
      $return_text = '<figure class="figure">
                                <a href="' . $img_path . '" data-lightbox="image-set" data-title="Path: ' . $value . '">
                                    <img src="' . $img_path . '" style="max-width:200px;" class="figure-img img-fluid rounded img-thumbnail" alt="">
                                </a>
                                <figcaption class="figure-caption">Path: ' . $value . '</figcaption>
                            </figure>';
    } else {
      $return_text = $value;
    }
    return $return_text;
  }
}
/*
 *
 * fielf_required
 * Show a * if field is required
 *
 * ------------------------------------------------------------------------
 */
if (!function_exists('fielf_required')) {
  /**
   * Prepare the Column Name for Lables.
   */
  function fielf_required($required)
  {
    $return_text = '';
    if ($required != '') {
      $return_text = '<span class="text-danger">*</span>';
    }
    return $return_text;
  }
}
/*
 * Get or Set the Settings Values
 *
 * @var [type]
 */
if (!function_exists('setting')) {
  function setting($key, $default = null)
  {
    if (is_null($key)) {
      return new App\Models\Setting();
    }
    if (is_array($key)) {
      return App\Models\Setting::set($key[0], $key[1]);
    }
    $value = App\Models\Setting::get($key);
    return is_null($value) ? value($default) : $value;
  }
}
/*
 * Show Human readable file size
 *
 * @var [type]
 */
if (!function_exists('humanFilesize')) {
  function humanFilesize($size, $precision = 2)
  {
    $units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
    $step = 1024;
    $i = 0;
    while (($size / $step) > 0.9) {
      $size = $size / $step;
      $i++;
    }
    return round($size, $precision) . $units[$i];
  }
}
/*
 *
 * Encode Id to a Hashids\Hashids
 *
 * ------------------------------------------------------------------------
 */
if (!function_exists('encode_id')) {
  /**
   * Prepare the Column Name for Lables.
   */
  function encode_id($id)
  {
    $hashids = new Hashids\Hashids(config('app.salt'), 3, 'abcdefghijklmnopqrstuvwxyz1234567890');
    $hashid = $hashids->encode($id);
    return $hashid;
  }
}
/*
 *
 * Decode Id to a Hashids\Hashids
 *
 * ------------------------------------------------------------------------
 */
if (!function_exists('decode_id')) {
  /**
   * Prepare the Column Name for Lables.
   */
  function decode_id($hashid)
  {
    $hashids = new Hashids\Hashids(config('app.salt'), 3, 'abcdefghijklmnopqrstuvwxyz1234567890');
    $id = $hashids->decode($hashid);
    if (count($id)) {
      return $id[0];
    } else {
      abort(404);
    }
  }
}
/*
 *
 * Prepare a Slug for a given string
 * Laravel default str_slug does not work for Unicode
 *
 * ------------------------------------------------------------------------
 */
if (!function_exists('slug_format')) {
  /**
   * Format a string to Slug.
   */
  function slug_format($string)
  {
    $base_string = $string;
    $string = preg_replace('/\s+/u', '-', trim($string));
    $string = str_replace('/', '-', $string);
    $string = str_replace('\\', '-', $string);
    $string = strtolower($string);
    $slug_string = substr($string, 0, 190);
    return $slug_string;
  }
}
/*
 *
 * icon
 * A short and easy way to show icon fornts
 * Default value will be check icon from FontAwesome (https://fontawesome.com)
 *
 * ------------------------------------------------------------------------
 */
if (!function_exists('icon')) {
  /**
   * Format a string to Slug.
   */
  function icon($string = 'fa-regular fa-circle-check')
  {
    $return_string = "<i class='" . $string . "'></i>&nbsp;";
    return $return_string;
  }
}
/*
 *
 * logUserAccess
 * Get current user's `name` and `id` and
 * log as debug data. Additional text can be added too.
 *
 * ------------------------------------------------------------------------
 */
if (!function_exists('logUserAccess')) {
  /**
   * Format a string to Slug.
   */
  function logUserAccess($text = '')
  {
    $auth_text = '';
    if (\Auth::check()) {
      $auth_text = 'User:' . \Auth::user()->name . ' (ID:' . \Auth::user()->id . ')';
    }
    \Log::debug(label_case($text) . " | $auth_text");
  }
}
/*
 *
 * bn2enNumber
 * Convert a Bengali number to English
 *
 * ------------------------------------------------------------------------
 */
if (!function_exists('bn2enNumber')) {
  /**
   * Prepare the Column Name for Lables.
   */
  function bn2enNumber($number)
  {
    $search_array = ['১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯', '০'];
    $replace_array = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
    $en_number = str_replace($search_array, $replace_array, $number);
    return $en_number;
  }
}
/*
 *
 * bn2enNumber
 * Convert a English number to Bengali
 *
 * ------------------------------------------------------------------------
 */
if (!function_exists('en2bnNumber')) {
  /**
   * Prepare the Column Name for Lables.
   */
  function en2bnNumber($number)
  {
    $search_array = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
    $replace_array = ['১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯', '০'];
    $bn_number = str_replace($search_array, $replace_array, $number);
    return $bn_number;
  }
}
/*
 *
 * bn2enNumber
 * Convert a English number to Bengali
 *
 * ------------------------------------------------------------------------
 */
if (!function_exists('en2bnDate')) {
  /**
   * Convert a English number to Bengali.
   */
  function en2bnDate($date)
  {
    // Convert numbers
    $search_array = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
    $replace_array = ['১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯', '০'];
    $bn_date = str_replace($search_array, $replace_array, $date);
    // Convert Short Week Day Names
    $search_array = ['Fri', 'Sat', 'Sun', 'Mon', 'Tue', 'Wed', 'Thu'];
    $replace_array = ['শুক্র', 'শনি', 'রবি', 'সোম', 'মঙ্গল', 'বুধ', 'বৃহঃ'];
    $bn_date = str_replace($search_array, $replace_array, $bn_date);
    // Convert Month Names
    $search_array = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    $replace_array = ['জানুয়ারী', 'ফেব্রুয়ারী', 'মার্চ', 'এপ্রিল', 'মে', 'জুন', 'জুলাই', 'আগষ্ট', 'সেপ্টেম্বর', 'অক্টোবর', 'নভেম্বর', 'ডিসেম্বর'];
    $bn_date = str_replace($search_array, $replace_array, $bn_date);
    // Convert Short Month Names
    $search_array = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
    $replace_array = ['জানুয়ারী', 'ফেব্রুয়ারী', 'মার্চ', 'এপ্রিল', 'মে', 'জুন', 'জুলাই', 'আগষ্ট', 'সেপ্টেম্বর', 'অক্টোবর', 'নভেম্বর', 'ডিসেম্বর'];
    $bn_date = str_replace($search_array, $replace_array, $bn_date);
    // Convert AM-PM
    $search_array = ['am', 'pm', 'AM', 'PM'];
    $replace_array = ['পূর্বাহ্ন', 'অপরাহ্ন', 'পূর্বাহ্ন', 'অপরাহ্ন'];
    $bn_date = str_replace($search_array, $replace_array, $bn_date);
    return $bn_date;
  }
}
/*
 *
 * banglaDate
 * Get the Date of Bengali Calendar from the Gregorian Calendar
 * By default is will return the Today's Date
 *
 * ------------------------------------------------------------------------
 */
if (!function_exists('banglaDate')) {
  function banglaDate($date_input = '')
  {
    if ($date_input == '') {
      $date_input = date('Y-m-d');
    }
    $date_input = strtotime($date_input);
    $en_day = date('d', $date_input);
    $en_month = date('m', $date_input);
    $en_year = date('Y', $date_input);
    $bn_month_days = [30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 29, 30];
    $bn_month_middate = [13, 12, 14, 13, 14, 14, 15, 15, 15, 16, 14, 14];
    $bn_months = ['পৌষ', 'মাঘ', 'ফাল্গুন', 'চৈত্র', 'বৈশাখ', 'জ্যৈষ্ঠ', 'আষাঢ়', 'শ্রাবণ', 'ভাদ্র', 'আশ্বিন', 'কার্তিক', 'অগ্রহায়ণ'];
    // Day & Month
    if ($en_day <= $bn_month_middate[$en_month - 1]) {
      $bn_day = $en_day + $bn_month_days[$en_month - 1] - $bn_month_middate[$en_month - 1];
      $bn_month = $bn_months[$en_month - 1];
      // Leap Year
      if (($en_year % 400 == 0 || ($en_year % 100 != 0 && $en_year % 4 == 0)) && $en_month == 3) {
        $bn_day += 1;
      }
    } else {
      $bn_day = $en_day - $bn_month_middate[$en_month - 1];
      $bn_month = $bn_months[$en_month % 12];
    }
    // Year
    $bn_year = $en_year - 593;
    if (($en_year < 4) || (($en_year == 4) && (($en_day < 14) || ($en_day == 14)))) {
      $bn_year -= 1;
    }
    $return_bn_date = $bn_day . ' ' . $bn_month . ' ' . $bn_year;
    $return_bn_date = en2bnNumber($return_bn_date);
    return $return_bn_date;
  }
}
/*
 *
 * Decode Id to a Hashids\Hashids
 *
 * ------------------------------------------------------------------------
 */
if (!function_exists('generate_rgb_code')) {
  /**
   * Prepare the Column Name for Lables.
   */
  function generate_rgb_code($opacity = '0.9')
  {
    $str = '';
    for ($i = 1; $i <= 3; $i++) {
      $num = mt_rand(0, 255);
      $str .= "$num,";
    }
    $str .= "$opacity,";
    $str = substr($str, 0, -1);
    return $str;
  }
}
/*
 *
 * Return Date with weekday
 *
 * ------------------------------------------------------------------------
 */
if (!function_exists('date_today')) {
  /**
   * Return Date with weekday.
   *
   * Carbon Locale will be considered here
   * Example:
   * শুক্রবার, ২৪ জুলাই ২০২০
   * Friday, July 24, 2020
   */
  function date_today()
  {
    $str = \Carbon\Carbon::now()->isoFormat('dddd, LL');
    return $str;
  }
}
if (!function_exists('language_direction')) {
  /**
   * return direction of languages.
   *
   * @return string
   */
  function language_direction($language = null)
  {
    if (empty($language)) {
      $language = app()->getLocale();
    }
    $language = strtolower(substr($language, 0, 2));
    $rtlLanguages = [
      'ar', //  'العربية', Arabic
      'arc', //  'ܐܪܡܝܐ', Aramaic
      'bcc', //  'بلوچی مکرانی', Southern Balochi
      'bqi', //  'بختياري', Bakthiari
      'ckb', //  'Soranî / کوردی', Sorani Kurdish
      'dv', //  'ދިވެހިބަސް', Dhivehi
      'fa', //  'فارسی', Persian
      'glk', //  'گیلکی', Gilaki
      'he', //  'עברית', Hebrew
      'lrc', //- 'لوری', Northern Luri
      'mzn', //  'مازِرونی', Mazanderani
      'pnb', //  'پنجابی', Western Punjabi
      'ps', //  'پښتو', Pashto
      'sd', //  'سنڌي', Sindhi
      'ug', //  'Uyghurche / ئۇيغۇرچە', Uyghur
      'ur', //  'اردو', Urdu
      'yi', //  'ייִדיש', Yiddish
    ];
    if (in_array($language, $rtlLanguages)) {
      return 'rtl';
    }
    return 'ltr';
  }
}
/*
 * Application Demo Mode check
 */
if (!function_exists('demo_mode')) {
  /**
   * Helper to grab the application name.
   *
   * @return mixed
   */
  function demo_mode()
  {
    $return_string = false;
    if (env('DEMO_MODE') == 'true') {
      $return_string = true;
    }
    return $return_string;
  }
}

C:\xampp82\htdocs\lva5\database\migrations\2023_10_24_020908_create_settings_table.php

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
  /**
   * Run the migrations.
   */
  public function up(): void
  {
    Schema::create('settings', function (Blueprint $table) {
      $table->id();
      $table->string('name')->nullable();
      $table->text('val')->nullable();
      $table->char('type', 20)->default('string');
      $table->integer('created_by')->unsigned()->nullable();
      $table->integer('updated_by')->unsigned()->nullable();
      $table->integer('deleted_by')->unsigned()->nullable();
      $table->timestamps();
      $table->softDeletes();
    });
  }
  /**
   * Reverse the migrations.
   */
  public function down(): void
  {
    Schema::dropIfExists('settings');
  }
};

C:\xampp82\htdocs\lva5\routes\web.php

<?php
use App\Http\Controllers\HomeController;
use App\Http\Controllers\SettingController;
use App\Http\Controllers\BackendController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/
Route::get('/', function () {
  return view('welcome');
});
Auth::routes();
Route::get('/home', [HomeController::class, 'index'])->name('home');
Route::group(['prefix' => 'admin', 'as' => 'backend.', 'middleware' => ['auth']], function () {
  /**
   * Backend Dashboard
   * Namespaces indicate folder structure.
   */
  Route::get("settings", [SettingController::class, 'index'])->name("settings");
  Route::post("settings", [SettingController::class, 'store'])->name("settings.store");
  Route::get('/', [BackendController::class, 'index'])->name('home');
  Route::get('dashboard', [BackendController::class, 'index'])->name('dashboard');
});

C:\xampp82\htdocs\lva5\composer.json

"autoload": {
    "psr-4": {
      "App\\": "app/",
      "Database\\Factories\\": "database/factories/",
      "Database\\Seeders\\": "database/seeders/"
    },
    "files": [
      "app/helpers.php"
    ]
  },

C:\xampp82\htdocs\lva5\vite.config.js

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
  plugins: [
    laravel({
      input: [
        'resources/sass/app-backend.scss',
        'resources/sass/app.scss',
        'resources/js/app.js',
      ],
      refresh: true,
    }),
  ],
  resolve: {
    alias: {
      '$': 'jQuery'
    },
  },
});

Source code

Last updated