how do I insert a different icon for each widgets - laravel

how do I insert a different icon for each widgets?
[
'type' => 'progress_white',
'class' => 'card mb-2',
'progressClass' => 'progress-bar bg-primary',
'value' => $userCount,
'description' => 'Utenti registrati.',
'progress' => (int)$userCount/10*100, // integer
'hint' => 'Numero di utenti registrati al portale.',
],
the html part is this this part below
<div class="{{ $widget['wrapperClass'] ?? 'col-sm-6 col-md-4' }}">
<div class="{{ $widget['class'] ?? 'card' }}">
<div class="card-body">
#if (isset($widget['value']))
<div class="text-value">{!! $widget['value'] !!}</div>
#endif
......

Unfortunately there is no way with the default widgets you will ave to create your own.
#if(isset($widget['icon']))
<div class="text-right" style="position:absolute;top:5px;right:15px;font-size: 40px;color: {{ $widget['icon_color'] ?? 'rgba(0,0,0,0.2)' }}">
<span class="{{ $widget['icon'] }}"></span>
</div>
#endif
Put that within the card-body class. Styling might need to be changed a little bit.
Other option is Backpack uses a new theme based on CoreUI. Can look at the documentation for CoreUI, or take a look at the source for the theme at https://backstrap.net

What kind of icons do you want? If you use icon set like material icon or awesome icon, you can pass your icon name and use it in "i" tag like this:
"icon" => "fa fa user"
and in your blade:
<i class"{{$widget['icon']}}"></i>

Related

Laravel locatization not translating

Okay so in my app.blade.php
<html>
<head>
//....
</head>
<body class="bg-black text-white flex flex-col min-h-screen page-{{ Route::currentRouteName() }}">
{{-- Navbar --}}
#include('layouts.navbar')
{{-- Page content --}}
<div class="flex-1">
#yield('content')
</div>
{{-- Footer --}}
#include('layouts.footer')
</body>
</html>
Now i want to use localization in the navbar so i did this (Lets call this block 1)
<div class="swiper-slide bg-primary"><div class="swiper-content mx-auto w-fit py-3 flex items-center gap-2"><i class="fas fa-concierge-bell"></i> {{ __('content/navbar.orange header 1') }}</div></div>
And thats working but now in the same file only 20 lines below the code above (Lets call this block 2)
{{ __('content/navbar.nav link 1') }}</div>
I have this line of code but its always translated in english. But the weird part is that when my locale is set to FR the content of block 1 shows in FR but the content of block 2 shows in EN eventhough they are in the same file
Im super confused and cant figure out why that is
Any help is welcome!
If u need more code let me know!
Content and structure of Lang file
Lang/en/content/navbar.php
Content of EN file
<?php
// lang/en/content/navbar.php
return [
'orange header 1' => 'Service to sold machines',
'orange header 2' => 'Large stock',
'orange header 3' => 'Transport to location',
'orange header 4' => 'Trade-in possible',
'nav link 1' => 'Home',
'nav link 2' => 'Stock',
'nav link 3' => 'Lease',
'nav link 4' => 'Contact',
];
Content of FR file (Lang/fr/content/navbar.php)
<?php
// lang/fr/content/navbar.php
return [
'orange header 1' => 'Service aux machines vendues',
'orange header 2' => 'Stock important',
'orange header 3' => "Transport à l'emplacement",
'orange header 4' => "Reprise possible",
'nav link 1' => 'Home',
'nav link 2' => 'Stock',
'nav link 3' => 'Louer',
'nav link 4' => 'Contact',
];
First image shows the page in fr and second image in en but the navbar content is still the same eventhough the uspbars content is translated
Ahhhh i had a piece of code between the uspsbar and navbar
<li onclick="{{ App::setLocale("en") }}" class="flex items-center gap-2 text-white text-lg font-bold">
<a class="flex items-center gap-2" href="{{ route('locale.setting', 'en') }}">
<img class="h-5 w-7" src="{{ asset('img/flags/EN-flag.png') }}" alt="EN-flag"> EN
</a>
</li>
But the onclick sets the locale to en and forgot to remove the onclick function, my bad!
Thanks everyone!!!

How can I make condition for class of x-jet-dialog-modal?

With laravel 8.68 and livewire 2.7 opening modal dialog (which can be used in many cases) I want
to change background color/color depending on parameter.
I try to change class in <x-jet-dialog-modal definition like :
<x-jet-dialog-modal wire:model="confirmActionModalProfileFormVisible"
class=" z-50 bg-opacity-100 #if($confirm_action_profile_modal_color === 'danger') personal_danger_text #else personal_text #endif">
But That does not work, and in browser's inspection I see that class in <x-jet-dialog-modal is not rendered,
I try to use alpinejs :
<x-jet-dialog-modal wire:model="confirmActionModalProfileFormVisible"
:class=" 'z-50 bg-opacity-100 ' + ( '{{$confirm_action_profile_modal_color }}' == 'danger' ? 'personal_danger_text' : 'personal_text' ) ">
But error was raised :
A non-numeric value encountered (View: my-template.blade.php)
Can I make condition for class of <x-jet-dialog-modal ?
UPDATED # 1:
Yes, I have jetstream views published , and I have file resources/views/vendor/jetstream/components/dialog-modal.blade.php,
which have default content :
#props(['id' => null, 'maxWidth' => null, 'class' => null])
<x-jet-modal :id="$id" :maxWidth="$maxWidth" {{ $attributes }} class="{{ !empty($class) ? $class : ''}}">
<div class="px-6 py-4 {{ !empty($class) ? $class : ''}}">
<div class="text-lg">
{{ $title }}
</div>
<div class="mt-4">
{{ $content }}
</div>
</div>
<div class="px-6 py-4 text-right {{ !empty($class) ? $class : ' bg-gray-100'}}">
{{ $footer }}
</div>
</x-jet-modal>
As I inheret my modal file from it I wonder in which way have I to edit definition of <x-jet-dialog-modal to pass
conditional class ?
Thanks in advance!
you have to publish jetstream views, then edit the file dialog-modal.blade.php and use the slot attributes.
Laravel Blade #Slot Attributes
If you want to change something from the modal itself, you would have to edit modal.blade.php
Edit the following line:
<div x-show="show" class="mb-6 bg-white rounded-lg overflow-hidden shadow-xl transform transition-all sm:w-full {{ $maxWidth }} sm:mx-auto">
And do attribute merge Laravel Blade #Deafault/Merged Attributes
another way will be to edit published JetStream modal window view (resources/views/vendor/jetstream/componets/modal.blade.php) and add {{$attributes['class']}} in class values. After that you can add any custom class or condition when including jetstream modal:
<x-jet-dialog-modal wire:model="myCustomModal" maxWidth="md" class="flex items-center my-custom-class">
and this will be applied on your modal. And now you should be able to use your conditions as well:
<x-jet-dialog-modal wire:model="myCustomModal" maxWidth="md" class="flex items-center my-custom-class #if($confirm_action_profile_modal_color === 'danger') personal_danger_text #else personal_text #endif">
nice example can be seen here:
https://floyk.com/en/post/how-to-use-laravel-jetstream-livewire-modal
or here:
https://floyk.com/en/post/livewire-5-ways-to-call-and-update-value-on-click

Illegal string offset Laravel 5.3

I'm trying to build a 'breadcrumb' thing dynamically using an array and this pass it to the view
In my controller
//build the breadcrumbs
$breadcrumbs = [
[
'link' => 'test link',
'name' => ''
]
];
return view('home',compact('breadcrumbs'));
the 'home.blade.php' extends the 'master.blade.php' where the
#include('_breadcrumbs')
resides. And here's the contents of '_breadcrumbs.blade.php'
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<ol class="breadcrumb">
<li #if(!isset($breadcrumbs))class="active"#endif>
<i class="fa fa-dashboard"></i> Dashboard
</li>
#if(isset($breadcrumbs))
#foreach($breadcrumbs as $b)
<li>{{$b['name']}}</li>
#endforeach
#endif
</ol>
</div>
</div>
<!-- /.row -->
but it gives me this error
Illegal string offset 'link' (View:
C:\laravel-projects\dinhi_ecommerce\resources\views_breadcrumbs.blade.php)
(View:
C:\laravel-projects\dinhi_ecommerce\resources\views_breadcrumbs.blade.php)\
If I do
dd(var_dump($breadcrumbs));
it gives me the contents of the array 'breadcrumbs' which means it does work in the controller part.
Any ideas, help please?
UPDATE:
I actually have a line where I modify the index 'name' in the array which I forgot to include in my post. Anyway I change it from
$breadcrumbs['name'] = categories::where('cat_id',$id)->first()->cat_name;
to
$breadcrumbs[0]['name'] = categories::where('cat_id',$id)->first()->cat_name;
and now its working :)

Laravel use an icon to delete content

I have the following delete button:
{!! Form::open(['route' => ['tasks.destroy', $type->id], 'method' => 'delete']) !!}
{!! Form::submit('Erase this task?', ['class' => 'delete']) !!}
{!!Form::close() !!}
And now I would like to not use a button, but an icon to delete content. I would like to use this button: http://fortawesome.github.io/Font-Awesome/3.2.1/icon/remove-sign/
<i class="icon-remove-sign"></i> icon-remove-sign
The sign should be blue and small.
How do I do that? I only get error messages relating to models as a result. But when I dont make any changes it works perfectly.
Can someone give me an example of how to make the picture point to a delete route?
The form helper does not allow you to add HTML to it. Use a simple HTML button:
{!! Form::open(['route' => ['tasks.destroy', $type->id], 'method' => 'delete']) !!}
<button class="delete">
<i class="icon-remove-sign"></i> Erase this task
</button>
{!!Form::close() !!}

Laravel locale translate paragraph

I'd like to ask if this is the correct way to translate a story:
'story' => 'This is a story about <br> peanut butter. <br> Peanut butter tastes good.'
Should I use <br> tags like above or is there another way?
Thanks,
g3
You could make "story" an array.
For example:
'story' => [
'This is a story about',
'peanut butter',
'Penut butter tastes good'
];
Then in your code:
#foreach($story as $paragraph)
{{ $paragraph }}<br>
#endforeach
This way also supports unlimited paragraphs, which can be an issue across translation barriers.
This is implemented in my website.
#foreach (trans('menus.benefits_menu') as $key => $translation)
<a href="{{ route('benefits', ['slug' => $key]) }}" class="{{ ($key == $uri) ? 'active' : ''}}">
<div class="name">{{ $translation }}</div>
</a>
#endforeach
You can see it working here: http://www.metinet.co/benefits/cloud_technology
(as the left hand menu)

Resources