data-bs-target with id not working in laravel - php

I have a modal pop out when pressing a button. Problem is, how do pass the value to the modal?
My table as shown in figure below. As you can see each row have different id. I wanted to get the id of a particular row after pressed the button.
The problem is how to display data in to bootstrap modal according to id. Thanks in advance.
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>ردیف</th>
<th>مقطع تحصیلی</th>
<th>رشته تحصیلی</th>
<th>تاریخ اخذ مدرک</th>
<th>جزییات بیشتر</th>
</tr>
</thead>
<tbody>
#foreach($user->educationals as $educational)
<tr>
<td class="fw-normal">{{ $educational->id }}</td>
<td class="fw-normal">{{ $educational->grade }}</td>
<td class="fw-normal">{{ $educational->major }}</td>
<td class="fw-normal">{{ $educational->end }}</td>
<td><a class="btn btn-link" data-bs-toggle="modal" data-bs-target="#educationals{{ $educational->id }}">جزییات بیشتر</a></td>
</tr>
#endforeach
</tbody>
</table>
</div>
#if(isset($educational))
<div class="modal fade" id="educationals{{ $educational->id }}" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="educationals{{ $educational->id }}" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="educationals{{ $educational->id }}">درخواست</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<table class="table">
<tr>
<th>مقطع تحصیلی</th>
<td>{{ $educational->grade }}</td>
</tr>
<tr>
<th>رشته تحصيلي</th>
<td>{{ $educational->major }}</td>
</tr>
<tr>
<th>معدل</th>
<td>{{ $educational->avg }}</td>
</tr>
<tr>
<th>تاريخ شروع</th>
<td>{{ $educational->start }}</td>
</tr>
<tr>
<th>تاريخ اخذ مدرك</th>
<td>{{ $educational->end }}</td>
</tr>
<tr>
<th>موسسه دريافت اخذ مدرك</th>
<td>{{ $educational->docPlaceName }}</td>
</tr>
<tr>
<th>عنوان پايان نامه / رساله</th>
<td>{{ $educational->thesisTitle }}</td>
</tr>
<tr>
<th>مدارك</th>
<td>{{ $educational->upload_doc }}</td>
</tr>
<tr>
<th>کشور محل دريافت مدرك</th>
<td>{{ $educational->docPlaceCountry }}</td>
</tr>
<tr>
<th>شهر محل دريافت مدرك</th>
<td>{{ $educational->docPlaceCity }}</td>
</tr>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">اوکی</button>
</div>
</div>
</div>
</div>
#else
<div class="alert alert-warning text-center" role="alert">
اطلاعاتی وجود ندارد.
</div>
#endif

You have many options but I suggest you to use javascript in any form you prefer. But if you don't want to use javascript, you should make model for each of table rows.
#foreach($user->educationals as $educational)
<div class="modal fade" id="educationals{{ $educational->id }}" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="educationals{{ $educational->id }}" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="educationals{{ $educational->id }}">درخواست</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<table class="table">
<tr>
<th>مقطع تحصیلی</th>
<td>{{ $educational->grade }}</td>
</tr>
<tr>
<th>رشته تحصيلي</th>
<td>{{ $educational->major }}</td>
</tr>
<tr>
<th>معدل</th>
<td>{{ $educational->avg }}</td>
</tr>
<tr>
<th>تاريخ شروع</th>
<td>{{ $educational->start }}</td>
</tr>
<tr>
<th>تاريخ اخذ مدرك</th>
<td>{{ $educational->end }}</td>
</tr>
<tr>
<th>موسسه دريافت اخذ مدرك</th>
<td>{{ $educational->docPlaceName }}</td>
</tr>
<tr>
<th>عنوان پايان نامه / رساله</th>
<td>{{ $educational->thesisTitle }}</td>
</tr>
<tr>
<th>مدارك</th>
<td>{{ $educational->upload_doc }}</td>
</tr>
<tr>
<th>کشور محل دريافت مدرك</th>
<td>{{ $educational->docPlaceCountry }}</td>
</tr>
<tr>
<th>شهر محل دريافت مدرك</th>
<td>{{ $educational->docPlaceCity }}</td>
</tr>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">اوکی</button>
</div>
</div>
</div>
</div>
#endforeach

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

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>

Blade Engine Elements Render Sorting

I have this code :
<div class="table-responsive">
<table class="table table-condensed table-hover">
<tr>
<th>#</th>
<th>Name</th>
<th>username</th>
<th>Email</th>
<th>Rank</th>
<th>Join</th>
</tr>
#if($count)
#foreach($users as $i => $user)
<tr>
<td>{{ $i+1 }}</td>
<td>{{ $user->first_name }} {{ $user->last_name }}</td>
<td>{{ $user->username }}</td>
<td>{{ $user->email }}</td>
<td>
#if($user->rank == 0)
Admin
#else
User
#endif
</td>
<td>{{ $user->created_at }}</td>
{{ Form::hidden('id', $user->id,['class'=>'id']) }}
{{ Form::hidden('username', $user->username,['class'=>'username']) }}
<td><button id="submit" type="button" class="btn btn-danger" data-toggle="modal" data-target="#deleteModal">
Delete
</button></td>
</tr>
#endforeach
#else
<div class="alert alert-success" style="text-align:center">
There is no users in the Site
</div>
#endif
which used Blade Template engine, but in case that's count is false the alert div appears before Heading of table
How can this problem be fixed ?
I may be missing something here, the code above seems incomplete (table is not closing). But why not move your alert outside of the other if so you can place it where you need it:
#if(!$count)
<div class="alert alert-success" style="text-align:center">
There is no users in the Site
</div>
#endif

Searching in db using Laravel 4.2

I want to search and display specific data from db and the method that I have made is not retrieving data from database, if i print it just gives a empty array.
My code is as follow:
Controller:
public function search() {
$search = Input::get('search');
if($search){
$query = DB::table('volunteer');
$results = $query ->where('bloodt', 'LIKE', $search) ->get();
//print_r($results); exit;
return View::make('search')->with("volunteer",$results);
}
}
View:
{{Form::open(array('method'=>'POST'))}}
<div class="pull-left col-xs-6 col-xs-offset-0">
{{Form::text('search','',array('placeholder'=>'Search by blood type/zip code/address....','class'=>'form-control','required autofocus'))}}
</div>
<input type="submit" name="search" value="Search" class="btn btn-primary">
<br><br>
{{Form::close()}}
<?php if (isset($results)) { ?>
#foreach($volunteer as $results)
<table class="table table-bordered" style="width: 100%; background-color: lightsteelblue">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>IC/Passport no.</th>
<th>Blood Type</th>
<th>Address</th>
<th>Zip Code</th>
<th>e-mail</th>
<th>Phone no.</th>
<th>Status</th>
</tr>
<tr>
<td>{{ $results->fname }}</td>
<td>{{ $results->lname }}</td>
<td>{{ $results->ic }}</td>
<td>{{ $results->bloodt }}</td>
<td>{{ $results->address }}</td>
<td>{{ $results->zipcode }}</td>
<td>{{ $results->email }}</td>
<td>{{ $results->phone }}</td>
<td>
<div class="btn-group" role="group">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">
{{ $results->status }}
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Eligible</li>
<li>Not Eligible</li>
</ul>
</div>
</td>
</tr>
</table>
#endforeach
<?php;
} ?>
Route:
Route::post('search', 'HomeController#search');

Categories