Relevant configuration : Php version 8 - laravel 8.
I have been trying to use laravel json translation without success and I don't understand how to make it work. The normal way using shorkeys works just fine as shown in the output below (pictures).
dashboard.blade.php :
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Dashboard') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 bg-white border-b border-gray-200">
You're logged in! {{ app()->getLocale() ." : " . __('30 Days') }}
</div>
<div class="p-6 bg-white border-b border-gray-200">
You're logged in! {{ app()->getLocale() ." : " . trans('30 Days') }}
</div>
<div class="p-6 bg-white border-b border-gray-200">
You're logged in! {{ app()->getLocale() ." : " . Lang::get('30 Days') }}
</div>
<div class="p-6 bg-white border-b border-gray-200">
You're logged in! {{ app()->getLocale() ." : " . __('auth.failed') }}
</div>
<div class="p-6 bg-white border-b border-gray-200">
You're logged in! {{ app()->getLocale() ." : " . trans('auth.failed') }}
</div>
<div class="p-6 bg-white border-b border-gray-200">
You're logged in! {{ app()->getLocale() ." : " . Lang::get('auth.failed') }}
</div>
</div>
</div>
</div>
auth.php :
return [
'failed' => 'Diese Kombination aus Zugangsdaten wurde nicht in unserer Datenbank gefunden.',
'password' => 'Das eingegebene Passwort ist nicht korrekt.',
'throttle' => 'Zu viele Loginversuche. Versuchen Sie es bitte in :seconds Sekunden nochmal.',
];
de.json :
{
"30 Days": "30 Tage",
"60 Days": "60 Tage",
"90 Days": "90 Tage",
":amount Total": ":amount Gesamt",
...rest of the translations,
}
Related
I have a Laravel 8 project. In this project, I wanted to pull the creators profile page from Algolia. That's why I integrated Algolia into the project. However, previously this creator profile pages worked in a different way. Then I integrated Algolia and started getting some errors because the names of the parts coming from Algolia and the parts coming from the old system differ. I started to fix these parts, but no matter what I did in one part, I couldn't handle it. I don't understand what mistake I am making because everything seems to be correct.
CreatorController
public function show($username)
{
$client = SearchClient::create(
env('ALGOLIA_APP_ID'),
env('ALGOLIA_SECRET'),
);
$indexUsers = $client->initIndex("users");
$creatorData = $indexUsers->search($username);
$creator = $creatorData["hits"][0] ?? null;
if(count($creatorData["hits"]) == 0 || !isset($creator)){
abort(404);
}
$indexContent = $client->initIndex("courses");
$contentData = $indexContent->search($username);
$contents = $contentData["hits"] ?? [];
if(count($contentData["hits"]) == 0 || !isset($contents)){
abort(404);
}
return view('creators.show',[
'creator' => (object)$creator,
'contents' => $contents,
]);
}
OLD show.blade.php - content section
#if($creator->contents->isNotEmpty())
<div class="bg-pippin p-8 rounded-lg">
<h4 class="text-2xl leading-8 font-semibold mb-8">Courses from the Author </h4>
<div class="space-y-8">
#foreach($creator->contents as $content)
<div class="flex items-center justify-between flex-col md:flex-row space-x-8">
#if($content->cover!=null)
<div class="w-full md:w-3/12 lg:w-2/6 mb-4 lg:mb-0">
<img src="{{ $content->cover }}" alt="{{ $content->name }}">
</div>
#endif
<div class="w-full md:w-9/12 lg:w-4/6">
<h3 class="font-argent text-4xl font-bold mb-6">{{ $content->name }}</h3>
#foreach($content->categories as $category)
<div class="inline-flex items-center px-3 py-2 rounded bg-soft-text mb-5">
<img src="https://app.omnicourse.io/{{ $category->icon}}" alt="">
<span class="text-base leading-6 font-normal text-white ml-2">{{ $category->name }}</span>
</div>
#endforeach
<div class="flex items-center space-x-6">
<div class="flex items-center">
<img src="/assets/images/icon-clock-black.svg" alt="">
<span class="text-sm md:text-base leading-6 font-normal ml-1">{{ $content->getLengthHours() }} hrs</span>
</div>
<div class="flex items-center">
<img src="/assets/images/icon-list-black.svg" alt="">
<span class="text-sm md:text-base leading-6 font-normal ml-1">{{ count($content->lectures) }} Lessons</span>
</div>
<!--div class="flex items-center">
<img src="/assets/images/icon-like-black.svg" alt="">
<span class="text-sm md:text-base leading-6 font-normal ml-1">96%</span>
</div -->
</div>
</div>
</div>
#endforeach
</div>
</div>
#endif
NEW show.blade.php - content section
#if(count($contents) > 0)
<div class="bg-pippin p-8 rounded-lg">
<h4 class="text-2xl leading-8 font-semibold mb-8">Courses from the Author </h4>
<div class="space-y-8">
#foreach($contents as $content)
<div class="flex items-center justify-between flex-col md:flex-row space-x-8">
#if($content['cover']!=null)
<div class="w-full md:w-3/12 lg:w-2/6 mb-4 lg:mb-0">
<img src="{{ $content['cover'] }}" alt="{{ $content['name'] }}">
</div>
#endif
<div class="w-full md:w-9/12 lg:w-4/6">
{{-- <h3 class="font-argent text-4xl font-bold mb-6">{{ $content->name }}</h3> --}}
#foreach($contents as $categorys)
<div class="inline-flex items-center px-3 py-2 rounded bg-soft-text mb-5">
<img src="https://app.omnicourse.io/{{ $categorys['icon'] }}" alt="">
<span class="text-base leading-6 font-normal text-white ml-2">{{ $category['name'] }}</span>
</div>
#endforeach
<div class="flex items-center space-x-6">
<div class="flex items-center">
<img src="/assets/images/icon-clock-black.svg" alt="">
<span class="text-sm md:text-base leading-6 font-normal ml-1">{{ $content->getLengthHours() }} hrs</span>
</div>
<div class="flex items-center">
<img src="/assets/images/icon-list-black.svg" alt="">
<span class="text-sm md:text-base leading-6 font-normal ml-1">{{ count($content->lectures) }} Lessons</span>
</div>
</div>
</div>
</div>
#endforeach
</div>
</div>
#endif
Data from Algolia and their names
{
"id": 114,
"user_id": 741,
"isLearnBite": 0,
"name": "Funding Your Business",
"cover": "https://omnicoursewebsites.s3.eu-west-2.amazonaws.com/courses/114/images/cover/769312_1643628130.jpg",
"color": "#fefefe",
"description": "Funding Your Business",
"short_description": "Funding Your Business",
"length": 5293,
"order": 0,
"status_id": 1,
"created_at": "2022-01-28T09:19:31.000000Z",
"updated_at": "2022-01-31T11:22:22.000000Z",
"custom_fields": {
"dynamic_link": "https://omnicourse.page.link/cQgs9TcoPen1J6dZ8"
},
"lectures_count": 22,
"lecturer_name": "Adam Shaw",
"lecturer_username": "adamshaw",
"lecturer_avatar": "https://omnicoursewebsites.s3.eu-west-2.amazonaws.com/creator_thumbnail/741/2022-03-29/thumbnail_400X400_565720_1640103825.jpg",
"tags": [
1,
30,
43,
73
],
"categories": [
2
],
"last_listened_data": null,
"user_rating": 0,
"isFavorited": false,
"isBookMarked": false,
"isCompleted": false,
"creator_profile": {
"name": "Adam Shaw",
"username": "adamshaw",
"avatar": "https://omnicoursewebsites.s3.eu-west-2.amazonaws.com/creator_thumbnail/741/2022-03-29/thumbnail_400X400_565720_1640103825.jpg",
"about": "What is important in life?\r\n\r\nI have asked myself this question for as long as I can remember. My path has been varied and fun, which for me is what makes life good.\r\n\r\nMy key expertise is working with energy and mind-body medicine. I also have a more recent background in funding and business consultancy.\r\n\r\nFor 13 years I worked as a nurse, developing key skills and awareness in counselling the dying and their families. Through discussing what was important in life with thousands of people close to death, I noticed certain patterns amongst the regrets and achievements of those close to death. \r\n\r\nIt also led me to discovering energy medicine through Reiki, Vortex Healing and Energetic NLP. This, in turn, led to a path into Mind-Body medicine.\r\n\r\nWhat does all of that mean for you though?\r\n\r\nIf you want to use your mind to improve your wellbeing, I can help. \r\n\r\nIf you are questioning your purpose on the planet, I can facilitate that journey.\r\n\r\nIf you are a company owner looking for help with funding, I can point you in the right direction.",
"custom_fields": {
"youtube": "https://www.youtube.com/c/AdamShawTheHeartGuy",
"linkedin": "https://www.linkedin.com/in/adamshawtheheartguy/",
"instagram": "https://www.instagram.com/the_heart_guy_/",
"twitter": "https://twitter.com/adam_shaw",
"website": "adamshaw.co",
"email_octopus_id": "ce1b2106-69ec-11ec-96e5-06b4694bee2a",
"email_octopus_last_update": "2022-03-26 00:46:46",
"avatar_thumb_400*400": "https://omnicoursewebsites.s3.eu-west-2.amazonaws.com/creator_thumbnail/741/2022-03-29/thumbnail_400X400_565720_1640103825.jpg"
}
},
"_tags": [
"App\\Course::114"
],
"objectID": "App\\Course::114"
}
I want to add my slider to my home page and when i add using #inclued method and it returns error undefended variable in slider page but it works well in slider page however i added it to home page error occurs. how do i correct this.
error msg-
Undefined variable $data (View: \resources\views\frontendslider.blade.php)
In the: \resources\views/frontendslider.blade.php file at line: 29
codes....
homepage
* LaraClassifier - Classified Ads Web Application
* Copyright (c) BeDigit. All Rights Reserved
*
* Website: https://laraclassifier.com
*
* LICENSE
* -------
* This software is furnished under a license and may be used and copied
* only in accordance with the terms of such license and with the inclusion
* of the above copyright notice. If you Purchased from CodeCanyon,
* Please read the full License from here - http://codecanyon.net/licenses/standard
--}}
#extends('layouts.master')
#section('search')
#parent
#includeFirst([config('larapen.core.customizedViewPath') . 'search.inc.form', 'search.inc.form'])
#endsection
#section('content')
<div class="main-container">
#includeFirst([config('larapen.core.customizedViewPath') . 'search.inc.breadcrumbs', 'search.inc.breadcrumbs'])
#if (config('settings.list.show_cats_in_top'))
#if (isset($cats) && $cats->count() > 0)
<div class="container mb-2 hide-xs">
<div class="row p-0 m-0">
<div class="col-12 p-0 m-0 border border-bottom-0 bg-light"></div>
</div>
</div>
#endif
#includeFirst([config('larapen.core.customizedViewPath') . 'search.inc.categories', 'search.inc.categories'])
#endif
<?php if (isset($topAdvertising) && !empty($topAdvertising)): ?>
#includeFirst([config('larapen.core.customizedViewPath') . 'layouts.inc.advertising.top', 'layouts.inc.advertising.top'], ['paddingTopExists' => true])
<?php
$paddingTopExists = false;
else:
if (isset($paddingTopExists) && $paddingTopExists) {
$paddingTopExists = false;
}
endif;
?>
<div class="container">
<div class="row">
{{-- Sidebar --}}
#if (config('settings.list.left_sidebar'))
#includeFirst([config('larapen.core.customizedViewPath') . 'search.inc.sidebar', 'search.inc.sidebar'])
<?php $contentColSm = 'col-md-9'; ?>
#else
<?php $contentColSm = 'col-md-12'; ?>
#endif
{{-- Content --}}
<div class="{{ $contentColSm }} page-content col-thin-left mb-4">
<div class="category-list {{ config('settings.list.display_mode', 'make-grid') }}{{ ($contentColSm == 'col-md-12') ? ' noSideBar' : '' }}">
<div class="tab-box">
{{-- Nav tabs --}}
<ul id="postType" class="nav nav-tabs add-tabs tablist" role="tablist">
<?php
$aClass = '';
$spanClass = 'alert-danger';
if (config('settings.single.show_listing_types')) {
if (!request()->filled('type') || request()->get('type') == '') {
$aClass = ' active';
$spanClass = 'bg-danger';
}
} else {
$aClass = ' active';
$spanClass = 'bg-danger';
}
?>
<li class="nav-item">
<a href="{!! qsUrl(request()->url(), request()->except(['page', 'type']), null, false) !!}" class="nav-link{{ $aClass }}">
{{ t('All Listings') }} <span class="badge badge-pill {!! $spanClass !!}">{{ $count->get('all') }}</span>
</a>
</li>
#if (config('settings.single.show_listing_types'))
#if (isset($postTypes) && $postTypes->count() > 0)
#foreach ($postTypes as $postType)
<?php
$postTypeUrl = qsUrl(
request()->url(),
array_merge(request()->except(['page']), ['type' => $postType->id]),
null,
false
);
$postTypeCount = ($count->has($postType->id)) ? $count->get($postType->id) : 0;
?>
#if (request()->filled('type') && request()->get('type') == $postType->id)
<li class="nav-item">
<a href="{!! $postTypeUrl !!}" class="nav-link active">
{{ $postType->name }}
<span class="badge badge-pill bg-danger">
{{ $postTypeCount }}
</span>
</a>
</li>
#else
<li class="nav-item">
<a href="{!! $postTypeUrl !!}" class="nav-link">
{{ $postType->name }}
<span class="badge badge-pill alert-danger">
{{ $postTypeCount }}
</span>
</a>
</li>
#endif
#endforeach
#endif
#endif
</ul>
<div class="tab-filter pb-2">
{{-- OrderBy Desktop --}}
<select id="orderBy" title="sort by" class="niceselecter select-sort-by small" data-style="btn-select" data-width="auto">
#if (isset($orderByArray) && !empty($orderByArray))
#foreach($orderByArray as $option)
#if ($option['condition'])
<option{{ $option['isSelected'] ? ' selected="selected"' : '' }} value="{!! $option['url'] !!}">
{{ $option['label'] }}
</option>
#endif
#endforeach
#endif
</select>
</div>
</div>
<div class="listing-filter">
<div class="float-start col-md-9 col-sm-8 col-12">
<h1 class="h6 pb-0 breadcrumb-list">
{!! (isset($htmlTitle)) ? $htmlTitle : '' !!}
</h1>
<div style="clear:both;"></div>
</div>
{{-- Display Modes --}}
#if (isset($posts) && $posts->count() > 0)
<?php $currDisplay = config('settings.list.display_mode'); ?>
<div class="float-end col-md-3 col-sm-4 col-12 text-end listing-view-action">
#if (isset($displayModesArray) && !empty($displayModesArray))
#foreach($displayModesArray as $displayMode => $value)
<span class="grid-view{{ ($currDisplay == $displayMode) ? ' active' : '' }}">
#if ($currDisplay == $displayMode)
<i class="fas fa-th-large"></i>
#else
<a href="{!! $value['url'] !!}">
<i class="{{ $value['icon'] }}"></i>
</a>
#endif
</span>
#endforeach
#endif
</div>
#endif
<div style="clear:both"></div>
</div>
{{-- Mobile Filter Bar --}}
<div class="mobile-filter-bar col-xl-12">
<ul class="list-unstyled list-inline no-margin no-padding">
#if (config('settings.list.left_sidebar'))
<li class="filter-toggle">
<a class=""><i class="fas fa-bars"></i> {{ t('Filters') }}</a>
</li>
#endif
<li>
{{-- OrderBy Mobile --}}
<div class="dropdown">
<a class="dropdown-toggle" data-bs-toggle="dropdown">{{ t('Sort by') }}</a>
<ul class="dropdown-menu">
#if (isset($orderByArray) && !empty($orderByArray))
#foreach($orderByArray as $option)
#if ($option['condition'])
<li>{{ $option['label'] }}</li>
#endif
#endforeach
#endif
</ul>
</div>
</li>
</ul>
</div>
<div class="menu-overly-mask"></div>
{{-- Mobile Filter bar End--}}
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="contentAll" role="tabpanel" aria-labelledby="tabAll">
<div id="postsList" class="category-list-wrapper posts-wrapper row no-margin">
<div class="slider">
#include('frontendslider')
</div>
#if (config('settings.list.display_mode') == 'make-list')
#includeFirst([config('larapen.core.customizedViewPath') . 'search.inc.posts.template.list', 'search.inc.posts.template.list'])
#elseif (config('settings.list.display_mode') == 'make-compact')
#includeFirst([config('larapen.core.customizedViewPath') . 'search.inc.posts.template.compact', 'search.inc.posts.template.compact'])
#else
#includeFirst([config('larapen.core.customizedViewPath') . 'search.inc.posts.template.grid', 'search.inc.posts.template.grid'])
#endif
</div>
</div>
</div>
<div class="tab-box save-search-bar text-center">
#if (request()->filled('q') && request()->get('q') != '' && $count->get('all') > 0)
<a id="saveSearch"
data-name="{!! qsUrl(request()->url(), request()->except(['_token', 'location']), null, false) !!}"
data-count="{{ $count->get('all') }}"
>
<i class="far fa-bell"></i> {{ t('Save Search') }}
</a>
#else
#endif
</div>
</div>
#if ($posts->hasPages())
<nav class="mt-3 mb-0 pagination-sm" aria-label="">
{!! $posts->appends(request()->query())->links() !!}
</nav>
#endif
</div>
</div>
</div>
{{-- Advertising --}}
#includeFirst([config('larapen.core.customizedViewPath') . 'layouts.inc.advertising.bottom', 'layouts.inc.advertising.bottom'])
{{-- Promo Listing Button --}}
<div class="container mb-3">
<div class="card border-light text-dark bg-light mb-3">
<div class="card-body text-center">
<h2>{{ t('do_you_have_anything') }}</h2>
<h5>{{ t('sell_products_and_services_online_for_free') }}</h5>
#if (!auth()->check() && config('settings.single.guests_can_post_listings') != '1')
{{ t('start_now') }}
#else
{{ t('start_now') }}
#endif
</div>
</div>
</div>
{{-- Category Description --}}
#if (isset($cat, $cat->description) && !empty($cat->description))
#if (!(bool)$cat->hide_description)
<div class="container mb-3">
<div class="card border-light text-dark bg-light mb-3">
<div class="card-body">
{!! $cat->description !!}
</div>
</div>
</div>
#endif
#endif
{{-- Show Posts Tags --}}
#if (config('settings.list.show_listings_tags'))
#if (isset($tags) && !empty($tags))
<div class="container">
<div class="card mb-3">
<div class="card-body">
<h2 class="card-title"><i class="fas fa-tags"></i> {{ t('Tags') }}:</h2>
#foreach($tags as $iTag)
<span class="d-inline-block border border-inverse bg-light rounded-1 py-1 px-2 my-1 me-1">
<a href="{{ \App\Helpers\UrlGen::tag($iTag) }}">
{{ $iTag }}
</a>
</span>
#endforeach
</div>
</div>
</div>
#endif
#endif
</div>
#endsection
#section('modal_location')
#includeFirst([config('larapen.core.customizedViewPath') . 'layouts.inc.modal.location', 'layouts.inc.modal.location'])
#endsection
#section('after_scripts')
<script>
$(document).ready(function () {
$('#postType a').click(function (e) {
e.preventDefault();
var goToUrl = $(this).attr('href');
redirect(goToUrl);
});
$('#orderBy').change(function () {
var goToUrl = $(this).val();
redirect(goToUrl);
});
});
</script>
#endsection
controller
public function frontendslider(Request $request){
$data=slider::all();
return view('frontendslider',compact('data'));
}
public function frontendslider2(Request $request){
$data=slider::all();
return view('return',compact('data'));
}
web.php
Route::get('frontendslider',[App\Http\Controllers\Admin\SliderController::class,'frontendslider']);
Route::get('return',[App\Http\Controllers\Admin\SliderController::class,'frontendslider2']);
Anyone face like this kind of issue specelly working with lara classifers use this before your importing page or page that content update..
#php
$data=DB::table('slider')->get();
#endphp
PLS note input your data to $data and table name!!!!
Hey I'm starting with php and symfony and something goes wrong when I'm trying to use Support's getter. Here is what I'm getting when I use dd($ticket) in showTicket function
empty (php): supportChats
Here, supportChats is empty.
But if I use dump(ticket) inside the view associated, here is what I have
isNotEmpty (twig): supportChats
Here, supportchats is NOT empty.
So, my question is: how it is possible ? i really need explanations please
Here is my showTicket function
#[Security("is_granted('ROLE_USER') and user === currentUser")]
#[Route('/user/profil/{username}/ticket/{ticket_id}', name: 'user.profile.ticket', methods: ['GET|POST'])]
#[ParamConverter('ticket', class: Support::class, options: ['id' => 'ticket_id'])]
public function showTicket(Request $request, User $currentUser, Support $ticket): Response
{
return $this->render('user/index.html.twig', [
'ticket' => $ticket,
'panelTicket' => 'show', // twig
'panel' => 'tickets', // js
'formUserPassword' => $this->createForm(UserPasswordType::class)->createView(),
'formTickets' => $this->createForm(TicketType::class)->createView()
]);
}
And finally the view associated
<div class="d-flex border border-danger border-start-0 border-end-0 text-light mb-5 w-75 mx-auto">
<div style="min-width: 25%" class="d-flex flex-column border-info text-center w-25">
<div class="border-bottom border-danger">{{ ticket.user.firstname }}</div>
<div>Posté le <br> {{ ticket.createdAt|format_datetime(locale='fr') }}</div>
</div>
<div class="d-flex border-start border-danger text-break p-2 w-100">
<div class="flex-grow-1">
{{ ticket.message }}
</div>
<div class="d-flex flex-column justify-content-center">
{% if ticket.supportChats|length == 0 %}
<a class="btn btn-danger align-self-center w-100" href="#">Modifier</a>
<a data-action="{{ path('user.profile', {username: app.user.username}) }}" data-id="{{ ticket.id }}" class="submit-update submit-update-ticket btn btn-danger align-self-center w-100 mt-1" name="delete-ticket" title="Supprimer le Ticket">Supprimer</a>
{% endif %}
{{dump(ticket)}}
Retour
</div>
</div>
</div>
I have a component using Laravel livewire which disappear after I submit the form inside of it.
Here is the blade content:
<div class="w-full flex flex-col justify-start items-start px-5 wow delay-100 fadeInUp">
<h3 class="w-full flex flex-row justif-start items-center text-center text-2xl font-medium text-gray-700 mt-5 mb-0">
{{ $survey->name }}
</h3>
<div class="w-full mt-5">
<div class="prose w-full max-w-full">
{!! $survey->description !!}
</div>
</div>
<form wire:submit.prevent="submit" class="w-full mt-10">
#foreach($survey->fields as $field)
<div class="w-full flex flex-col justify-start items-start gap-2 mb-10" wire:key="field{{ $field->id }}">
<span class="font-medium" #class([
'text-gray-700',
'text-danger-700' => $errors_list && $errors_list->has($field->slug)
])>
{{ $field->name }}
#if($field->is_required)
<sup class="font-medium text-danger-700">*</sup>
#endif
</span>
<div class="prose w-full max-w-full">
{!! $field->description !!}
</div>
<div class="w-full">
#switch($field->type)
#case('text')
<div class="w-full flex flex-row justify-start items-center gap-2">
{{ html()->text($field->slug)->class($field_class)->attribute('wire:model.defer', 'model.' . $field->slug) }}
</div>
#break;
#case('textarea')
<div class="w-full flex flex-row justify-start items-center gap-2">
{{ html()->textarea($field->slug)->class($field_class)->attribute('wire:model.defer', 'model.' . $field->slug) }}
</div>
#break;
#case('select')
<div class="w-full flex flex-row justify-start items-center gap-2">
{{ html()->select($field->slug, explode(',', $field->values))->class($field_class)->attribute('wire:model.defer', 'model.' . $field->slug) }}
</div>
#break;
#case('multiselect')
<div class="w-full flex flex-row justify-start items-center gap-2">
{{ html()->multiselect($field->slug, explode(',', $field->values))->class($field_class)->attribute('wire:model.defer', 'model.' . $field->slug) }}
</div>
#break;
#case('file')
<div class="w-full flex flex-row justify-start items-center gap-2">
{{ html()->file($field->slug) }}
</div>
#break;
#case('checkbox')
#foreach(explode(',', $field->values) as $value)
<div class="w-full flex flex-row justify-start items-center gap-2" wire:key="{{ $field->slug . '_' . $value }}">
{{ html()->checkbox($field->slug, false, $value)->id($field->slug . '_' . $value)->attribute('wire:model.defer', 'model.' . $field->slug) }}
{{ html()->label($value, $field->slug . '_' . $loop->index)->class('p-0') }}
</div>
#endforeach
#break;
#case('radio')
#foreach(explode(',', $field->values) as $value)
<div class="w-full flex flex-row justify-start items-center gap-2" wire:key="{{ $field->slug . '_' . $value }}">
{{ html()->radio($field->slug, false, $value)->id($field->slug . '_' . $value)->attribute('wire:model.defer', 'model.' . $field->slug) }}
{{ html()->label($value, $field->slug . '_' . $loop->index)->class('p-0') }}
</div>
#endforeach
#break;
#case('date')
<div class="w-full flex flex-row justify-start items-center gap-2">
{{ html()->date($field->slug, null, __('Y-m-d'))->class($field_class)->attribute('wire:model.defer', 'model.' . $field->slug) }}
</div>
#break;
#case('datetime')
<div class="w-full flex flex-row justify-start items-center gap-2">
{{ html()->datetime($field->slug, null, __('Y-m-d g:i A'))->class($field_class)->attribute('wire:model.defer', 'model.' . $field->slug) }}
</div>
#break;
#case('time')
<div class="w-full flex flex-row justify-start items-center gap-2">
{{ html()->time($field->slug, null, __('g:i A'))->class($field_class)->attribute('wire:model.defer', 'model.' . $field->slug) }}
</div>
#break;
#endswitch
</div>
</div>
#endforeach
<div class="w-full flex flex-row justify-start items-center gap-2">
<button type="submit" class="px-3 py-1 text-white bg-fprimary hover:text-fprimary hover:bg-white border border-fprimary rounded">
{{ __('Submit') }}
</button>
</div>
</form>
</div>
And the submit function, is only checking the errors:
protected function rules(): array
{
return $this->survey->form_rules;
}
public function submit()
{
$this->validate();
}
All works well before the line $this->validate(), after I call this function the component disappear from the rendered view.
But if the form is valid and no errors are fired when form is validated, all works well.
FYI, I am rendering the livewire component in a blade page:
<livewire:survey :survey="$survey"></livewire:survey>
I know this issue is already discussed in other questions, but I tried all the solutions without getting it work.
I found the solution which is simply to remove the <div> element that contains all the other elements and leave the <form> element as the root.
So now I have the following code in my blade file:
<form wire:submit.prevent="submit" class="w-full mt-10 w-full flex flex-col justify-start items-start">
<h3 class="w-full flex flex-row justif-start items-center text-center text-2xl font-medium text-gray-700 mt-5 mb-0">
{{ $survey->name }}
</h3>
<div class="w-full mt-5 mb-10">
<div class="prose w-full max-w-full">
{!! $survey->description !!}
</div>
</div>
#foreach($survey->fields as $field)
<div class="w-full flex flex-col justify-start items-start gap-2 mb-10" wire:key="field{{ $field->id }}">
<span class="font-medium #if($errors->has('model.' . $field->slug)) text-danger-700 #else text-gray-700 #endif">
{{ $field->name }}
#if($field->is_required)
<sup class="font-medium text-danger-700">*</sup>
#endif
</span>
<div class="prose w-full max-w-full">
{!! $field->description !!}
</div>
<div class="w-full">
#switch($field->type)
#case('text')
<div class="w-full flex flex-row justify-start items-center gap-2">
{{ html()->text($field->slug)->class($field_class)->attribute('wire:model.defer', 'model.' . $field->slug) }}
</div>
#break;
#case('textarea')
<div class="w-full flex flex-row justify-start items-center gap-2">
{{ html()->textarea($field->slug)->class($field_class)->attribute('wire:model.defer', 'model.' . $field->slug) }}
</div>
#break;
#case('select')
<div class="w-full flex flex-row justify-start items-center gap-2">
{{ html()->select($field->slug, explode(',', $field->values))->class($field_class)->attribute('wire:model.defer', 'model.' . $field->slug) }}
</div>
#break;
#case('multiselect')
<div class="w-full flex flex-row justify-start items-center gap-2">
{{ html()->multiselect($field->slug, explode(',', $field->values))->class($field_class)->attribute('wire:model.defer', 'model.' . $field->slug) }}
</div>
#break;
#case('file')
<div class="w-full flex flex-row justify-start items-center gap-2">
{{ html()->file($field->slug) }}
</div>
#break;
#case('checkbox')
#foreach(explode(',', $field->values) as $value)
<div class="w-full flex flex-row justify-start items-center gap-2" wire:key="{{ $field->slug . '_' . $value }}">
{{ html()->checkbox($field->slug, false, $value)->id($field->slug . '_' . $value)->attribute('wire:model.defer', 'model.' . $field->slug) }}
{{ html()->label($value, $field->slug . '_' . $loop->index)->class('p-0') }}
</div>
#endforeach
#break;
#case('radio')
#foreach(explode(',', $field->values) as $value)
<div class="w-full flex flex-row justify-start items-center gap-2" wire:key="{{ $field->slug . '_' . $value }}">
{{ html()->radio($field->slug, false, $value)->id($field->slug . '_' . $value)->attribute('wire:model.defer', 'model.' . $field->slug) }}
{{ html()->label($value, $field->slug . '_' . $loop->index)->class('p-0') }}
</div>
#endforeach
#break;
#case('date')
<div class="w-full flex flex-row justify-start items-center gap-2">
{{ html()->date($field->slug, null, __('Y-m-d'))->class($field_class)->attribute('wire:model.defer', 'model.' . $field->slug) }}
</div>
#break;
#case('datetime')
<div class="w-full flex flex-row justify-start items-center gap-2">
{{ html()->datetime($field->slug, null, __('Y-m-d g:i A'))->class($field_class)->attribute('wire:model.defer', 'model.' . $field->slug) }}
</div>
#break;
#case('time')
<div class="w-full flex flex-row justify-start items-center gap-2">
{{ html()->time($field->slug, null, __('g:i A'))->class($field_class)->attribute('wire:model.defer', 'model.' . $field->slug) }}
</div>
#break;
#endswitch
</div>
#error('model.' . $field->slug)
<span class="text-sm font-medium text-danger-700">{{ $message }}</span>
#enderror
</div>
#endforeach
<div class="w-full flex flex-row justify-start items-center gap-2">
<button type="submit" class="px-3 py-1 text-white bg-fprimary hover:text-fprimary hover:bg-white border border-fprimary rounded">
{{ __('Submit') }}
</button>
</div>
</form>
If anyone can give me some information about why this change made it works it will be great, because I don't understand why having a <div> element as root element didn't work, and <form> works.
FYI, I have other pages containing <div> root element and all is working just fine.
Hello i'm using inani larapoll it's works great but in admin panel i can't see results of voting i can see only question, how many answers it have and how many vote was added i want to create custom page in admin where will be results of current vote like it is on WEB
like this
question - > why its don't working
answer1 -> don't know <- this option has 10 votes
answer2 -> because i'm doing something wrong <- this option has 100 votes
i added route
Route::get('/results', ['uses' => 'PollManagerController#results', 'as' => 'poll.results']);
pollmanager controller
public function results(Poll $poll)
{
$total = $poll->votes->count();
$results = $poll->results()->grab();
$options = collect($results)->map(function ($result) use ($total){
return (object) [
'votes' => $result['votes'],
'percent' => $total === 0 ? 0 : ($result['votes'] / $total) * 100,
'name' => $result['option']->name
];
});
$question = $poll->question;
echo view(config('larapoll_config.results') ? config('larapoll_config.results') : 'larapoll::dashboard.results', compact('options', 'question'));
}
and i copied results blade to my new blade
#if(Session::has('errors'))
<div class="alert alert-danger">
{{ session('errors') }}
</div>
#endif
#if(Session::has('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
#endif
<div class="w-80 m-auto">
<div class="font-size-14 font-medium-caps text-blue-100">{{ $question }}</div>
#foreach($options as $option)
<div class="mt-20px">
<div class="font-size-14 font-size-xs-12 text-blue-100">{{ $option->name }}</div>
<div class="w-100 d-flex justify-content-between pb-5px">
<div class="w-100 d-flex align-items-center">
<div class="w-100 bg-lighter-gray h-4px position-relative">
<div class="position-absolute top-0 bg-yellow h-4px" style='width: {{ $option->percent }}%'> </div>
</div>
</div>
<div class="font-size-14 font-size-xs-12 text-blue-100 pl-10px">{{ $option->percent }}%</div>
</div>
</div>
#endforeach
<div class="d-flex justify-content-between mt-auto pt-30px align-items-center">
<div class="d-flex">
<span class="fas fa-calendar text-light-gray pr-5px"></span>
<p class="mr-20px font-medium font-size-12 text-light-gray"></p>
</div>
<div class="d-flex align-items-center text-light-black flex-end font-base font-size-14 font-size-xs-12"></div>
</div>
</div>
but's its showing nothing... empty