Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Bottelet/DaybydayCRM

2311 stars
4 code files
View Bottelet/DaybydayCRM on GitHub

app/helpers.php

Open in GitHub
// You just create a file listing all the global methods you need, without any class
// Just in case, you may check if that function already exists somewhere else
 
if (! function_exists('frontendDate')) {
function frontendDate(): String
{
return app(\App\Repositories\Format\GetDateFormat::class)->getFrontendDate();
}
}
 
if (! function_exists('isDemo')) {
function isDemo(): String
{
return app()->environment() == "demo" ? 1 : 0;
}
}
 
if (! function_exists('formatMoney')) {
function formatMoney($amount, $useCode = false): String
{
return app(\App\Repositories\Money\MoneyConverter::class, ['money' => $amount])->format($useCode);
}
}

composer.json

Open in GitHub
// To register the helper file, it needs to be in "autoload" section of composer.json
 
{
"name": "bottelet/daybyday-crm",
"require": {
"php": ">=7.3.9",
"aws/aws-sdk-php": "^3.112",
// ...
},
"autoload": {
"files": [
"app/helpers.php"
],
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Tests\\": "tests/"
}
},
 
// ...
}

resources/views/auth/login.blade.php

Open in GitHub
// We can use Helper method like isDemo() in any Blade file
 
@extends('layouts.app')
@section('content')
 
@if(isDemo())
<div class="alert alert-info">
<strong>Demo login info</strong>
<p>Email: demo@daybydaycrm.com</p>
<p>Password: Daybydaycrm123</p>
</div>
@endif
 
@endsection

app/Http/Middleware/RedirectIfDemo.php

Open in GitHub
// And we can use Helper in Middleware, for example
 
class RedirectIfDemo
{
const MEESAGE = 'This action is not allowed in the demo.';
 
public function handle($request, Closure $next)
{
if(!isDemo()) {
return $next($request);
}
 
Session()->flash('flash_message_warning', __(self::MEESAGE));
return redirect()->back();
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.