After selecting one person, selected person must dissappear from options - php

In the group table I select a person from the list, but after selecting one name, his name should not appear in other select options, it must show 'selected' or just disappear, so names in groups cant duplicate, 1name=1slot.
In the students list below, there must be a group's name assigned to a person if he/she is selected.
View for a better understanding
My groups dropdown blade:
<div class="row">
#for ($groupName = 1; $groupName <= $project->amount; $groupName++)
<div class="col-3">
<table class="table table-bordered table-sm table-hover text-center my-3">
<tr class="table-light">
<th> Group #{{ $groupName }} </th>
</tr>
<tr>
<td>
#for ($j = 0; $j < $project->studentsPerGroup; $j++)
<select class="form-select form-select-sm" style="overflow:auto; max-height:260;">
<option selected>Assign Student</option>
#foreach ($students as $student)
<option value="{{ $groupName }}">{{ ucwords($student->name) }} {{ $loop->iteration . '/' . $loop->count }}</option>
#endforeach
</select>
#endfor
</td>
</tr>
</table>
</div>
#endfor
</div>
And persons list table:
enter code her<table class="table table-bordered table-sm table-hover text-center my-3">
<tr class="table-light">
<th>Student</th>
<th>Group Name</th>
<th width="220px">Action</th>
</tr>
#foreach ($students as $student)
<tr class="align-middle">
<td class="text-left">{{ ucwords($student->name) }}</td>
<td>Group#</td>
<td>
<form action="{{ route('students.destroy', $student->id) }}" method="POST">
#csrf
#method('DELETE')
<button type="submit" title="delete" class="btn btn-danger btn-sm" onclick="return confirm('Please Confirm')">
Remove
</button>
</form>
</td>
</tr>
#endforeach
</table>
It's a school project and I really tried hard. Any help is appreciated.

Related

Trying to get property 'name' of non-object (View: C:\xampp\htdocs\AppLaravel\resources\views\admin\editBill.blade.php)

I need to go to my bill list page but this error is stopping me: 'Trying to get property 'name' of non-object'
My route:
Route::get('bill/{id?}',[
'as'=>'bill',
'uses'=>'PageController#editBill'
]);
My Controller:
public function editBill($id)
{
$customerInfo=DB::table('customer')->select('customer.id','customer.name','customer.created_at','customer.phone_number','customer.address','customer.note','bills.total','customer.email')->join('bills','bills.id_customer','=','customer.id')->where('customer.id', '=', $id)->first();
$billInfo=Bill::where('id',$id)->get();
return view('admin.editBill',compact('customerInfo','billInfo'));
}
My view:
<section class="content">
<!-- Default box -->
<div class="box">
<div class="box-header with-border">
<div class="row">
<div class="col-md-12">
<div class="container123 col-md-6" style="">
<h4></h4>
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-4">Customer Info</th>
<th class="col-md-6"></th>
</tr>
</thead>
<tbody>
<tr>
<td>Customer name</td>
<td>{{ $customerInfo->name }}</td>
</tr>
<tr>
<td>Date Order</td>
<td>{{ $customerInfo->created_at }}</td>
</tr>
<tr>
<td>Phone Number</td>
<td>{{ $customerInfo->phone_number }}</td>
</tr>
<tr>
<td>Address</td>
<td>{{ $customerInfo->address }}</td>
</tr>
<tr>
<td>Email</td>
<td>{{ $customerInfo->email }}</td>
</tr>
<tr>
<td>Note</td>
<td>{{ $customerInfo->note }}</td>
</tr>
</tbody>
</table>
</div>
<table id="myTable" class="table table-bordered table-hover dataTable" role="grid" aria-describedby="example2_info">
<thead>
<tr role="row">
<th class="sorting col-md-1" >Id</th>
<th class="sorting_asc col-md-4">Product name</th>
<th class="sorting col-md-2">Quantity</th>
<th class="sorting col-md-2">Unit_price</th>
</thead>
<tbody>
#foreach($billInfo as $key=>$bill)
<tr>
<td>{{ $key+1 }}</td>
<td>{{ $bill->product }}</td>
<td>{{ $bill->quantity }}</td>
<td>{{ number_format($bill->unit_price) }} VNĐ</td>
</tr>
#endforeach
<tr>
<td colspan="3"><b>Total</b></td>
<td colspan="1"><b class="text-red">{{ number_format($customerInfo->total) }} đ</b></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-md-12">
<form action="{{route('pdf',$customerInfo->id)}}" method="GET">
<input type="hidden" name="_method" value="PUT">
{{ csrf_field() }}
<div class="col-md-8"></div>
<div class="col-md-4">
<div class="form-inline">
<label>Delivery Status: </label>
<select name="status" class="form-control input-inline" style="width: 200px">
<option value="1">None</option>
<option value="2">On going</option>
<option value="2">Delivered</option>
</select>
<input type="submit" method="get" value="Print" class="btn btn-primary">
</div>
</div>
</form>
</div>
</div>
</div>
</section>
The bill detail list is working fine but the customers detail is not
I tried others way like {{$customer->name ?? ''}} and it did't give an error anymore but it doesn't show any data

i want to check all my checkbox from one checkbox using laravel 8 mvc

I want to check the first checkbox that have the id checkAll and it will check all my checkboxes and when I unchecked it, it will unchecked all too.
My blade index.blade.php:
<body>
<table class="table">
<thead>
<tr>
<th scope="col">
<input type="checkbox" id="checkAll">
</th>
<th scope="col">id</th>
<th scope="col">title</th>
<th scope="col">Paragraph</th>
</tr>
</thead>
#foreach ($categories as $categorie)
<tbody>
<tr>
<td>
<input type="checkbox" name="checkOne" value="{{$categorie->id}}">
</td>
<th scope="row">{{ $categorie->id }}</th>
<td>{{ $categorie->Title }}</td>
<td>{{ $categorie->Paragraph }}</td>
<form action={{ route('categorie.destroy', $categorie->id) }} method="POST">
#csrf
#method('DELETE')
<td>
<button class="btn btn-danger" type="submit">
delete
</button>
</form>
<button class="btn btn-warning"> <a href={{ route('edit', $categorie->id) }}>edit</a> </button>
</td>
</tr>
</tbody>
#endforeach
</table>
</body>
If you have multiple checkboxes with the same name then use array in your loop, as below:
<input type="checkbox" name="checkOne[]" value="{{ $categorie->id }}">
Now you need to use jQuery to select/unselect checkboxes, use below code:
$('#checkAll').change(function() { // main checkbox id
$('input[name="checkOne[]"]').prop('checked', $(this).is(":checked"));
});
Try this code -
<script type='text/javascript'>
function checkAll(e) {
const checkboxes = document.getElementsByName('checkOne');
for (let i = 0; i < checkboxes.length; i++) {
checkboxes[i].checked = e.checked;
}
}
</script>

can I use my controller in laravel 8 to delet row that checked in view?

#extends('layouts.app')
#section('content')
<body>
<button class="btn" onclick="deleteSelected()">delete</button>
<table class="table">
<thead>
<tr>
<th scope="col">
<input type="checkbox" id="all" onclick="chkd()">
</th>
<th scope="col">id</th>
<th scope="col">title</th>
<th scope="col">Paragraph</th>
</tr>
</thead>
#foreach ($categories as $categorie)
<tbody>
<tr>
<td>
<input type="checkbox" class="ss" value="{{ $categorie->id }}" onclick="deleteSelected()">
</td>
<th scope="row">{{ $categorie->id }}</th>
<td>{{ $categorie->Title }}</td>
<td>{{ $categorie->Paragraph }}</td>
<form action={{ route('categorie.destroy', $categorie->id) }} method="POST">
#csrf
#method('DELETE')
<td>
<button id="deleteRow" class="btn btn-danger" type="submit" style="display: none">
delete
</button>
</form>
<button class="btn btn-warning"> <a href={{ route('edit', $categorie->id) }}>edit</a> </button>
</td>
</tr>
</tbody>
#endforeach
</table>
</body>
#endsection
that is my view , when I check one of my checkbox and press the button delete I want this row to be deleted or when I checked all I want to delete all row
I think html input must inside the form. How about moving code like this:
#foreach ($categories as $categorie)
<tbody>
<tr>
<td>
<form action={{ route('categorie.destroy', $categorie->id) }} method="POST">
#csrf
#method('DELETE')
<input type="checkbox" class="ss" value="{{ $categorie->id }}" onclick="deleteSelected()">
<button id="deleteRow" class="btn btn-danger" type="submit" style="display: none">
delete
</button>
</form>
</td>
<th scope="row">{{ $categorie->id }}</th>
<td>{{ $categorie->Title }}</td>
<td>{{ $categorie->Paragraph }}</td>
<td><button class="btn btn-warning"> <a href={{ route('edit', $categorie->id) }}>edit</a> </button></td>
</tr>
</tbody>
#endforeach
But, I don't know this is can fix your case or not. I can't see the whole code

Disable Button if Variants are empty

So I have this forelse that displays all the variants, now what I want to happen is that, if there is no variant. the submit button will be disabled.
<table class="table table-striped">
<thead>
<tr>
<th class="col-sm-5">Name</th>
<th class="col-sm-1">Default?</th>
<th class="col-sm-2 text-right">Retail Price</th>
<th class="col-sm-2 text-right">Quantity</th>
<th class="col-sm-2"></th>
</tr>
</thead>
<tbody>
#forelse ($product->variants as $index => $variant)
<tr>
<td>{{ $variant->name }}</td>
<td>{{ $variant->is_default ? 'Yes' : 'No' }}</td>
<td class="text-right">{{ number_format($variant->retail_price, 2) }} {{ $variant->price_currency }}</td>
<td class="text-right">{{ number_format($variant->quantity, 0) }}</td>
<td>Edit</td>
</tr>
#empty
<tr>
<td colspan="5">No variants found</td>
<?php $varbutton = 'disabled';?>
</tr>
#endforelse
</tbody>
</table>
here is the button
<div class="panel-footer">
<button class="btn btn-default" type="submit"<?php $varbutton; ?>>Update Store</button>
</div>
Is it possible using php and html in the blade alone or do I have to do it in the controller?
You should be using blade in your button:
<div class="panel-footer">
<button class="btn btn-default" type="submit" {{ $varbutton }}>Update Store</button>
</div>
Also please note that there needs to be a space after "submit".
Or, if you don't want that space when the button is not disabled, use:
<?php $varbutton = ' disabled';?>
<div class="panel-footer">
<button class="btn btn-default" type="submit"{{ $varbutton }}>Update Store</button>
</div>

POST method of <form> is not working inside #foreach on blade file in laravel 5.6

Button doesnot work after using form inside #foreach. Any suggestion about how to use form inside a #foreach loop ?
is it even possible to use form inside a loop in laravel blade file?
here is my code of my laravel blade file. I have used form inside foreach for getting data of Book Amount. Any Suggestion about how to solve this problem?
#extends('layouts.app')
#section('content')
<div class="container">
<h1>Items On Cart:</h4>
<div class="row justify-content-center">
<div class="col-md-12">
<div class="card">
<div class="card-body">
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
<table style="border-collapse: collapse;width: 100%;">
<tr style="border: 1px solid #dddddd;text-align: left;padding: 8px;font-size:20px;color: gray">
<th>Book Name</th>
<th>Author Name</th>
<th>Book Amount</th>
<th>Price</th>
<th>Action</th>
<th>Action</th>
</tr>
#foreach($cart_items as $data)
<form action="{{ route('change_item_amount',[$cart_info->id,$data->book_id]) }}" method="POST">
<tr>
<th>{{ show_books_name($data->book_id) }}</th>
<th>{{ show_books_author($data->book_id) }}</th>
<th><input type="number" name="amount" id="amount" value="{{ $data->item_amount }}"></th>
<th>{{ $data->price }} tk</th>
<th><button type="submit" class="btn btn-success">Change</button></th>
<th><a class="btn btn-success" href="{{ route('delete_book',[$cart_info->id,$data->book_id] ) }}">Delete</a></th>
</form>
#endforeach
</table>
</div>
<h2 style="padding-left:865px">Total = {{ $cart_info->total_price }} tk</h2>
</div>
</form>
</div>
</div>
</div>
#endsection
The simplest solution can be: place a form tag into a td, (btw it should be td, not th, you use th in thead):
<table style="border-collapse: collapse;width: 100%;">
<tr style="border: 1px solid #dddddd;text-align: left;padding: 8px;font-size:20px;color: gray">
<th>Book Name</th>
<th>Author Name</th>
<th>Book Amount</th>
<th>Price</th>
<th>Action</th>
<th>Action</th>
</tr>
#foreach($cart_items as $data)
<tr>
<td>{{ show_books_name($data->book_id) }}</td>
<td>{{ show_books_author($data->book_id) }}</td>
<td> <!-- Here we have empty td now --> </td>
<td>{{ $data->price }} tk</td>
<td>
<!-- Form is here now -->
<form action="{{ route('change_item_amount',[$cart_info->id,$data->book_id]) }}" method="POST">
<input type="number" name="amount" id="amount" value="{{ $data->item_amount }}">
<button type="submit" class="btn btn-success">Change</button>
</form>
</td>
<td><a class="btn btn-success" href="{{ route('delete_book',[$cart_info->id,$data->book_id] ) }}">Delete</a></td>
#endforeach
</table>

Categories