I am creating wizard systeem i create taks and wizard. but i want to show the take as stap not all the taks in one stap.
<div class="slide" id="slide-2" style="display: none">
#foreach($tasks as $task)
<div class="form-group">
<label for="task[{{ $loop->index }}]">{{ $task->name }</label>
<input type="checkbox" name="task[]" id="task[{{ $loop->index }}]" value="{{ $task->id }}">
</div>
#endforeach
</div>
But now I get all task in one time, how can I get one by one?
$tasks is an array and you can get array value one by one by key or index
for example:
$tasks[0]->name display first index of $tasks name or $tasks[0]->id
and $tasks[1]->name to get second and ...
of course there are many ways to get values , it depends on how do you want to use it
for loop or switch or other loops with conditions
Related
I have a page that displays all the records from the 'Receita' table like this:
public function mostrarTodos()
{
$receitas = Receita::all()->toArray();
$ingredientes = Ingrediente::all()->toArray();
return view('home', compact('receitas', 'ingredientes'));
}
on the top of the page there is a form with many checkboxes that will filter the results displayed on the front page:
<div class="col-span-2 border p-2">
<form action="filtro" class="grid grid-cols-4" method="GET">
#foreach ($ingredientes as $ingrediente)
<div>
<label for="{{ $ingrediente['id'] }}">{{ $ingrediente['nome'] }}</label>
<input type="checkbox" name="ingrediente[]" id="{{ $ingrediente['id'] }}" value="{{ $ingrediente['id'] }}">
</div>
#endforeach
<button class="rounded p-2 bg-purple-200 col-span-4" type="submit">Filtrar</button>
</form>
</div>
The question is, how can I use that form to filter the results that are displayed on the page since each entry can have one or many of those checkboxes? In other words, show me only the entries that have the checked checkboxes.
I have a laravel project. it has a table that I want to fill with data from a form. Currently it populates the form with any data that may exist in the table.
I'm using #foreach to iterate through the data object. This works fine when there is data in the table, but when there's no data obviously the #foreach data object will be empty.. How do folk handle this so that the form still shows with default values?
#foreach($pricing as $price)
<div class="form-row align-items-center">
<div class="col-12">
<p><strong>Rate</strong></p>
</div>
<div class="col-12">
<div class="row">
<div class="col-md-2">
<label for="hirePrice" class="">Hire Price</label>
</div>
<div class="col-md-4">
<input type="text" name="hire" class="form-control" placeholder="1200" aria-label="hireprice" id="hirePrice" value="{{ $price->hire}}">
Currently, if I empty the table, the page just displays the header and none of the html above, including the form fields.
edit: The table will always only have 1 ROW !! not sure if this makes it any easier.
You can use
#isset($pricing)
#foreach($pricing as $price)
<div class="form-row align-items-center">
<div class="col-12">
<p><strong>Rate</strong></p>
.................................
//your code
#endforeach
#endisset
Or, You can use if else condition like this:
#if($pricing != Null)
#foreach($pricing as $price)
<div class="form-row align-items-center">
<div class="col-12">
<p><strong>Rate</strong></p>
.....................
//code
#endforeach
#else
<div>No data</div>
#endif
Though i can not get your actual scenario,i can give some advice.
You can add one line condition inside of input tag like this:
HTML:
<input type="text" #if($data->variable) value="{{ $data->variable }}" #else value=" " #endif >
Otherwise, You can put same code within foreach loop into else condition. So, when data exists in the table, it shows the data in the form otherwise same form with empty value will appear.
I have 2 collections, $all have all the values (5), and $some has only 2 values. I'm trying to this:
For each value of $all, if that item in the loop is in the $some collection, put the the value of that $some item (something like that) in the input:
#foreach($all as $item)
<div>
#if(in_array($item->id, $some))
<input type="number" value="{{ Here I need to put the value of $some where id of some be teh same of $all }}">
#else
<input type="number" value="0">
#endif
</div>
#endforeach
I don't know how to read and decide all that inside the blade.
EDIT: I was trying something like this:
#if(in_array($item->id, $some))
<input type="number" value="{{ $some->find($item->id)->value }}">
I don't know what the specific fields are on $some, but you can do what you want (replacing the fields you need to compare or show) like this:
#if(in_array($item->id, $some->pluck('id')->toArray()))
<input type="number" value="{{ $some->where('id', $item->id)->first()->fieldYouWant}}">
#else
<input type="number" value="0">
#endif
Basically, pull the $some ids into an array, compare the current looped $item->id (from $all), and if it hits, pull the specific $some object that matched (id from $some, and id from current $all item) and get the value you need from whatever the field you need is called.
In my case, i was trying to do this on a array of checkboxes input, in case someone needs it this way:
<input type="checkbox" name="guides[]" value="{{ $item->id }}"
{{ in_array($item->id, $some->pluck('id')->toArray()) ? 'checked' : '' }} >
Suppose i have some subjects which has conditions and groups.
How can i load those first time and checked in update mood in vuejs?
<div v-for="(sub, Index) in subjects">
<b>{{ sub }} </b>
<label v-for="(subconlist) in sub['subCon']">
<input type="checkbox"
:value="subconlist.id"
:key="subconlist.id"
>
<span>{{subconlist.name}} </span>
</label>
<label v-for="clsgrlist in sublist['acGr']">
<input type="checkbox">
<span>{{clsgrlist.academic_group_name}} </span>
</label>
</div>
<button #click="saveOrUpdate()" >Save </button>
</div>
fiddle here
the table where i will save it : sub_id,condition_ids,group_ids
I have to save data based on checked value in the table with comma separated.
How can i get checkbox checked if it already found in the table, i mean when update?
I need to get subjectconditon or group ids basis on each subject when click on save button.
I'm currently making a CMS, for a local charity (free of charge) and I'm using Laravel 5.6 along with Zurb foundation 6.4. It's my first time using Laravel, but I've really enjoyed it and I've almost finished.
However, I have a couple of little niggles, that I need to fix, before I deploy it and a little guidance would help, a lot. I'm stuck with assigning a dynamic ID to my modal, to update. My controller, route and model are fine. I can update the first record, from the table, with the modal and that works as expected.
The problem is, it is always the first record that is shown, irrespective of whether I click the trigger, on an unrelated row. I've tried to pass the category_id in, using Blade, but that doesn't work, I either get the same result or an error. I can see what the problem is, but I don't know how to fix it. I think I need some jQuery and/or Ajax and I have tried, to no avail (I'm rubbish with JS).
As I said, my MVC is sound, I can update the first row and all I need is to be able to dynamically assign the category_id to the data-open attribute. I'll post my code, below and thanks for taking time to read this.
#foreach ($categories as $category)
<tr>
<td>{{ $category->name }}</td>
<td>{{ $category->posts->count() }}</td>
<td align="center"><a data-open="editModal"><i class="fas fa-edit fa-lg" style="color: green"></i></a></td>
<td align="center">
<i class="fas fa-trash-alt fa-lg" style="color: red"></i>
</td>
</tr>
<div class="reveal" id="editModal" data-reveal>
<h3>Edit: {{ $category->name }}</h3>
<form action="{{ route('category.update', ['id' => $category->id]) }}" method="post">
{{ csrf_field() }}
<label for="name">Category Name</label>
<input type="text" name="name" value="{{ $category->name }}">
<button class="button expanded success fullRadiusButton" type="submit">Update Category</button>
<i class="fas fa-window-close"></i>
</form>
</div>
#endforeach
An element is unique in the document based on the id property but you're using the same id (editModal) multiple times. You're instructing the Reveal Modal library to open the modal with an id of editModal so it finds the first one (which it expects to be the only one) and opens it. An id should only ever appear once in a document, or you'll experience unexpected behaviour like this.
id - unique to a single element
class - not unique to an element
You can fix this by giving each edit modal a unique id, something like this:
<div class="reveal" id="editModal_{{ $category->id }}" data-reveal>
Then in your trigger reference that unique id:
<a data-open="editModal_{{ $category->id }}">