cannot delete last data on table using laravel destroy function - php

I create a laravel destroy function and i use a modal to delete data. but i cannot delete all data in my database. last one cannot be deleted. i think it cause in view.
this is my modal popup in view
<div class="modal fade" id="delete-form" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Delete Account</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form id="delete-form" action="{{ route('account.destroy', [$account->id]) }}" method="post">
<input type="hidden" name="_method" value="delete">
{{ csrf_field() }}
<p>Are you sure you want to delete this data? </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div>
</div>
And my destroy controller
public function destroy(Account $account)
{
$findAccount = Account::find($account->id);
if($findAccount->delete()){
return redirect()->route('account.index')->with('success', 'Account details delete successfully!');
}
return back()->withInput()->with('error', 'Account details could not be deleted.');
}
i cannot delete all data in table. they keep one data and it cannot be deleted.

Try this:
#extends('template.app')
#section('content')
<div class="col-md-9">
<!-- table content -->
<div class="card">
<div class="card-header main-color-bg">
<h3 class="card-title">Account Details</h3>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-12">
<input class="form-control rounded-corner" type="text" placeholder="Search Member Here" style="margin-bottom: 20px;">
</div>
</div>
<!-- success message -->
#include('inc.message')
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Account Number</th>
<th scope="col">Type</th>
<th scope="col">Amount</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
#if(is_empty($accounts))
<tr><td>NO DATA</td></tr>
#else
#foreach($accounts as $account)
<tr>
<th scope="row">{{$account->id}}</th>
<td>{{$account->acc_no}}</td>
<td>{{$account->acc_type}}</td>
<td>{{$account->amount}}</td>
<td><a class="btn btn btn-secondary" href="{{route('account.edit', $account->id)}}"><span class="fa fa-pencil"></span> Edit</a> <a class="btn btn btn-danger"
data-toggle="modal" data-target="#delete-form"><span class="fa fa-trash-o"></span> Delete</a></td>
</tr>
#endforeach
#endif
</tbody>
</table>
<!-- pagination -->
<nav id="pagination">
<ul class="pagination justify-content-center">
<li class="page-item disabled">
<span class="page-link"><span class="fa fa-arrow-circle-left"></span></span>
</li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item active">
<span class="page-link">
2
<span class="sr-only">(current)</span>
</span>
</li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item">
<a class="page-link" href="#"><span class="fa fa-arrow-circle-right"></span></a>
</li>
</ul>
</nav>
<!-- end pagination -->
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#myModal"><span class="fa fa-plus"></span> Add Account</button>
</div>
</div>
<!-- end table content -->
</div>
<!-- delete modal -->
<!-- Modal -->
<div class="modal fade" id="delete-form" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Delete Account</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form id="delete-form" action="{{ route('account.destroy', [$account->id]) }}" method="delete">
<input type="hidden" name="_method" value="delete">
{{ csrf_field() }}
<p>Are you sure you want to delete this data? </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div>
</div>
<!-- end delete modal-->
<!-- modal popup -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header" style="background-color: #309fe2; color: #fff;">
<h5 class="modal-title" id="exampleModalLabel">Account Details</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
{!! Form::open(['url' => '/account', 'id' => 'eventForm', 'data-toggle' => 'validator', 'role' => 'form']) !!}
{{ csrf_field() }}
<div class="modal-body">
<!-- modal form -->
<div class="form-group">
<label for="acc_no">Account Number</label>
<input type="number" class="form-control" name="acc_no" id="acc_no" maxlength="20" placeholder="Enter your account number" required>
</div>
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" maxlength="30" name="name" id="name" placeholder="Enter your name" required>
</div>
<div class="form-group">
<label for="id_no">Identity No</label>
<input type="number" class="form-control" maxlength="9" name="id_no" id="id_no" placeholder="Enter your identity no" required>
</div>
<div class="form-group">
<label for="bank_id">Bank</label>
<select class="form-control" name="bank_id">
#if(!empty($banks))
#foreach($banks as $bank)
<option value="{{ $bank->id }}">{{ $bank->name }}</option>
#endforeach
#endif
</select>
</div>
<div class="form-group">
<label for="acc_type">Account Type</label>
<select class="form-control" id="acc_type" name="acc_type">
<option value="Saving">Saving</option>
<option value="Current">Current</option>
<option value="Deposite">Deposite</option>
</select>
</div>
<div class="form-group">
<label for="amount">Amount</label>
<input type="text" pattern="[0-9.]" class="form-control" maxlength="15" name="amount" id="amount" placeholder="Enter your amount" required>
</div>
<!-- end modal form -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal"><span class="fa fa-times-circle"></span> Close</button>
<button type="submit" class="btn btn-primary pull-right"><span class="fa fa-money"></span> Save changes</button>
</div>
{!! Form::close() !!}
</div>
</div>
</div>
<!-- end modal -->
#endsection

On your delete form change method from POST to DELETE.

I think may be Account::find($account->id); did not get the right Account object. use findOrFail to have another shot:
public function destroy(Account $account)
{
$findAccount = Account::findOrFail($account->id);
...
}

this is my table view. where i put if statement
#foreach($accounts as $account)
<tr>
<th scope="row">{{$account->id}}</th>
<td>{{$account->acc_no}}</td>
<td>{{$account->acc_type}}</td>
<td>{{$account->amount}}</td>
<td><a class="btn btn btn-secondary" href="{{route('account.edit', $account->id)}}"><span class="fa fa-pencil"></span> Edit</a> <a class="btn btn btn-danger"
data-toggle="modal" data-target="#delete-form"><span class="fa fa-trash-o"></span> Delete</a></td>
</tr>
#endforeach

#extends('template.app')
#section('content')
<div class="col-md-9">
<!-- table content -->
<div class="card">
<div class="card-header main-color-bg">
<h3 class="card-title">Account Details</h3>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-12">
<input class="form-control rounded-corner" type="text" placeholder="Search Member Here" style="margin-bottom: 20px;">
</div>
</div>
<!-- success message -->
#include('inc.message')
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Account Number</th>
<th scope="col">Type</th>
<th scope="col">Amount</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
#if(!empty($accounts))
#foreach($accounts as $account)
<tr>
<th scope="row">{{$account->id}}</th>
<td>{{$account->acc_no}}</td>
<td>{{$account->acc_type}}</td>
<td>{{$account->amount}}</td>
<td><a class="btn btn btn-secondary" href="{{route('account.edit', $account->id)}}"><span class="fa fa-pencil"></span> Edit</a> <a class="btn btn btn-danger"
data-toggle="modal" data-target="#delete-form"><span class="fa fa-trash-o"></span> Delete</a></td>
</tr>
#endforeach
#endif
</tbody>
</table>
<!-- pagination -->
<nav id="pagination">
<ul class="pagination justify-content-center">
<li class="page-item disabled">
<span class="page-link"><span class="fa fa-arrow-circle-left"></span></span>
</li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item active">
<span class="page-link">
2
<span class="sr-only">(current)</span>
</span>
</li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item">
<a class="page-link" href="#"><span class="fa fa-arrow-circle-right"></span></a>
</li>
</ul>
</nav>
<!-- end pagination -->
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#myModal"><span class="fa fa-plus"></span> Add Account</button>
</div>
</div>
<!-- end table content -->
</div>
<!-- delete modal -->
<!-- Modal -->
<div class="modal fade" id="delete-form" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Delete Account</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form id="delete-form" action="{{ route('account.destroy', [$account->id]) }}" method="delete">
<input type="hidden" name="_method" value="delete">
{{ csrf_field() }}
<p>Are you sure you want to delete this data? </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div>
</div>
<!-- end delete modal-->
<!-- modal popup -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header" style="background-color: #309fe2; color: #fff;">
<h5 class="modal-title" id="exampleModalLabel">Account Details</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
{!! Form::open(['url' => '/account', 'id' => 'eventForm', 'data-toggle' => 'validator', 'role' => 'form']) !!}
{{ csrf_field() }}
<div class="modal-body">
<!-- modal form -->
<div class="form-group">
<label for="acc_no">Account Number</label>
<input type="number" class="form-control" name="acc_no" id="acc_no" maxlength="20" placeholder="Enter your account number" required>
</div>
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" maxlength="30" name="name" id="name" placeholder="Enter your name" required>
</div>
<div class="form-group">
<label for="id_no">Identity No</label>
<input type="number" class="form-control" maxlength="9" name="id_no" id="id_no" placeholder="Enter your identity no" required>
</div>
<div class="form-group">
<label for="bank_id">Bank</label>
<select class="form-control" name="bank_id">
#if(!empty($banks))
#foreach($banks as $bank)
<option value="{{ $bank->id }}">{{ $bank->name }}</option>
#endforeach
#endif
</select>
</div>
<div class="form-group">
<label for="acc_type">Account Type</label>
<select class="form-control" id="acc_type" name="acc_type">
<option value="Saving">Saving</option>
<option value="Current">Current</option>
<option value="Deposite">Deposite</option>
</select>
</div>
<div class="form-group">
<label for="amount">Amount</label>
<input type="text" pattern="[0-9.]" class="form-control" maxlength="15" name="amount" id="amount" placeholder="Enter your amount" required>
</div>
<!-- end modal form -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal"><span class="fa fa-times-circle"></span> Close</button>
<button type="submit" class="btn btn-primary pull-right"><span class="fa fa-money"></span> Save changes</button>
</div>
{!! Form::close() !!}
</div>
</div>
</div>
<!-- end modal -->
#endsection

Related

Modal do not want to open - Bootstrap

I want to make my modal apper, but I can not to do it.
This is my code:
<div class="container h-100">
<div class="row justify-content-sm-center h-100">
<div class="col-xxl-4 col-xl-5 col-lg-5 col-md-7 col-sm-9">
<div class="text-center my-5">
<img src="img/logo-branca.png" alt="logo" width="100">
</div>
<div class="card shadow-lg">
<div class="card-body p-5">
<h1 class="fs-4 card-title fw-bold mb-4">CEP</h1>
<form method="POST" action = "autenticar.php">
<div class="mb-3">
<input id="cep" type="number" class="form-control" name="cep" value="" required="required">
</div>
<button type="submit" class="btn btn-primary ms-auto">
Pesquisar
</button>
</div>
</form>
</div>
<div class="card-footer py-3 border-0">
<div class="text-center">
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#staticBackdrop">
BUTTON TO OPEN THE MODAL
</button>
</div>
</div>
</div>
<div class="text-center mt-5 text-muted">
Copyright © 2021 — Rodrigo Franco
</div>
</div>
</div>
</div>
And this my modal:
<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="staticBackdropLabel">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Understood</button>
</div>
</div>
</div>
</div>
If you need to see my project compleatly, just go to this link or if you want to make download the project, just go here
You are not loading Bootstrap's javascript files, simply add:
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
To the head of your document and the modal works.
Resources: https://getbootstrap.com/docs/5.0/components/modal/

Limit the activated image in laravel

I am doing the CMS.. How should I able to limit the activated images with message? For example I would like to limit 5 activated image and I also would like to put some message if he exceed to the limit like "Only 5 activated images only!"
I already tried this but the message wont display(I also checked the $result).. Is there something wrong in my codes? What is it?
View
#extends('dashboard')
#section('content')
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">Upload New Image</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="titleLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header modal-header-success">
<button type="button" class="close btn btn-primary" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="titleLabel">New Image</h4>
</div>
<div class="modal-body">
<div class="container">
<div class="panel-body">
<div class="text-content">
<div class="col-md-2 col-lg-5">
<br>
#if($errors->first('image'))
<p class="errors">
<div class = "alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
{!!$errors->first('image')!!}
</ul>
</div>
</p>
#endif
#if ($message = Session::get('failed'))
<div class="alert alert-success alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
</div>
#endif
<h4>Choose to Upload:</h4>
<div class="col-md-2 col-lg-2">
<form action="{{ url('file-upload') }}" enctype="multipart/form-data" method="POST">
{{ csrf_field() }}
<div class="row">
<div class="col-md-12">
<input type="file" class = "filestyle"name="image" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<span class="pull-right">
<button type="submit" class="btn btn-success">Upload File</button>
</span>
</form>
</div>
</div>
</div>
</div>
<br><br>
#if ($message = Session::get('success'))
<div class="alert alert-success alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
</div>
#endif
<div class="x_content">
<table class="table table-hover">
<thead>
<tr>
<th>#</th>
<th>Image</th>
<th>Action</th>
<th>Status</th>
</tr>
</thead>
<tbody>
#foreach($data as $image)
<tr>
<th scope="row">{{ $image->id }}</th>
<td><img src="/assets/img/{{$image->img_jumbotron}}" width ="50px"> </td>
<td>
#if($image->status=="Activated")
<form action="/deactivateImage/{{ $image->id}}" method="post">
<input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
<button type="submit" class="btn btn-primary">Deactivate</button>
</form>
#else
<form action="{{ url('activateImage', ['id' => $image->id]) }}" method="post">
<input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
<button type="submit" class="btn btn-primary">Activate</button>
</form>
</td>
#endif
<td>{{$image->status}}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
#stop
Controller
public function activateImage($id)
{
$result = jumbotron::where(['status' => 'Activated'])->count();
if($result > 5)
{
return back()->with('failed', 'Only 5 images can be activated!');
}
else
{
echo "not yet";die;
}
return back()->with('activated','Image Activated successfully.');
}
You should return redirect():
return redirect()->back()->with('failed', 'Only 5 images can be activated!');

Delete button for each row with restriction

I have two tables in mysql database, the first one is 'kavomati' where are coffee machines and second table is 'lokacije' where are locations of those coffee machines. I created one page where I see all locations and there I have modal button for add new location, modal buttons for edit each location and at the end of each address I added delete modal button for each row. What I want to do is to delete every location which has no coffee machine but first I must make a query in php and check is certain location have any coffee machine. I'm newbie in php and this is my homework problem so I would appreciate any help.
This is my code to display locations of my database table and modal buttons:
<?php
if(!isset($_SESSION['user_id'])){
header('Location: ../../index.php');
}
try{
$stmt = $conn->prepare('SELECT id,ulica,kc_broj,mjesto FROM lokacije ORDER BY id ASC');
$stmt->execute();
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
catch(PDOException $e){
if(DEBUG === true){
header('Location:error/db_error.php?err_msg='.$e->getMessage());
}
else{
header('Location:error/db_error.php?err_msg');
}
}
?>
<div class="panel-heading clearfix">
<h3 style="float:left; margin:0;">Lokacije</h3>
Dodaj lokaciju
</div>
<table class="table table-hover">
<tr>
<th>ID</th>
<th>Ulica</th>
<th>Kućni broj</th>
<th>Mjesto</th>
<th></th>
</tr>
<?php
foreach($data as $value){
?>
<tr>
<td>
<?php echo $value['id'].'.'?>
</td>
<td>
<?php echo $value['ulica']?>
</td>
<td>
<?php echo $value['kc_broj']?>
</td>
<td>
<?php echo $value['mjesto']?>
</td>
<td align="right">
<a href="#" data-toggle="modal" data-target="#edit_loc<?php echo $value['id']?>" role="button" class="btn btn-success btn-sm edit">
<i class="fa fa-pencil-square-o"></i> Uredi
</a>
<div class="modal fade edit-u" id="edit_loc<?php echo $value['id']?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content" style="text-align:left;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Uredi lokaciju broj <?php echo $value['id']?></h4>
</div>
<form action="" method="POST">
<div class="modal-body">
<input type="hidden" name="id_lokacije" id="id_lokacije" value="<?php echo $value['id']?>">
<div class="form-group ulica">
<label for="ulica">Ulica</label>
<input type="text" class="form-control" name="ulica" id="ulica-u" placeholder="Ostavite prazno polje ako ne želite mjenjati naziv kavomata" value="">
</div>
<div class="form-group kc_broj">
<label for="kc_broj">Kućni broj</label>
<input type="text" class="form-control" name="kc_broj" id="kc_broj-u" placeholder="Ostavite prazno polje ako ne želite mjenjati naziv kavomata" value="">
</div>
<div class="form-group mjesto">
<label for="mjesto">Mjesto</label>
<input type="text" class="form-control" name="mjesto" id="mjesto-u" placeholder="Ostavite prazno polje ako ne želite mjenjati naziv kavomata" value="">
</div>
</div>
</form>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Zatvori</button>
<button type="button" class="btn btn-primary" id="edit_loc">Spremi</button>
</div>
</div>
</div>
</div>
<a href="#" data-toggle="modal" data-target="#delete_loc<?php echo $value['id']?>" role="button" class="btn btn-danger btn-sm">
<i class="fa fa-trash-o"></i> Izbriši
</a>
<div class="modal fade" id="delete_loc<?php echo $value['id']?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content" style="text-align:center;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h2 class="modal-title" id="myModalLabel" style="color:#a80b27;text-transform:uppercase;font-size:1.6rem;">upozorenje !</h2>
</div>
<div class="modal-body">
<h5>Da li si siguran da želiš obrisati lokaciju broj <b><?php echo $value['id']?></b>?</h5>
</div>
<div class="modal-footer">
<a href="include/locations/delete.php?id=<?php echo $value['id']?>" role="button" class="btn btn-danger">
Da, siguran sam!
</a>
<button type="button" class="btn btn-default" data-dismiss="modal">Ne</button>
</div>
</div>
</div>
</div>
</td>
</tr>
<?php
}
?>
</table>
<div class="modal fade" id="add_locModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Dodaj novu lokaciju</h4>
</div>
<form action="" method="POST">
<div class="modal-body">
<div class="form-group ulica">
<label for="ulica">Ulica</label>
<input type="text" class="form-control" name="ulica" id="ulica" placeholder="Ulica">
</div>
<div class="form-group kc_broj">
<label for="kc_broj">Kućni broj</label>
<input type="text" class="form-control" name="kc_broj" id="kc_broj" placeholder="Kućni broj">
</div>
<div class="form-group mjesto">
<label for="mjesto">Mjesto</label>
<input type="text" class="form-control" name="mjesto" id="mjesto" placeholder="Mjesto">
</div>
</div>
</form>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Zatvori</button>
<button type="button" class="btn btn-primary" id="add_loc">Dodaj</button>
</div>
</div>
</div>
And this is my delete.php script:
require '../../config/init.php';
require '../services/xss.php';
if(isset($_SESSION['user_id']) && isset($_GET['id'])){
$id = $_GET['id'];
try{
$stmt = $conn->prepare('DELETE FROM lokacije WHERE id=:id NOT IN(SELECT k.id FROM kavomati k WHERE k.id=lokacije.id)');
$stmt->bindParam(':id',$id);
$stmt->execute();
header('Location:../../coffee-locations.php');
}
catch(PDOException $e){
if(DEBUG === true){
header('Location:../../error/db_error.php?err_msg='.$e->getMessage());
}
else{
header('Location:../../error/db_error.php?err_msg');
}
}
}
else{
header('Location:../../index.php');
}
?>
I tried something like this but it doesn't work.

create class and object of that in laravel 5.3

I am using laravel 5.3 for my project. I have a panel bootstrap that have some cart in that. each cart has some feature. i want to define a cart class and create new object of that with button using jquery.
I am new in laravel.
I found, i can use #include for use cart in my code,but i cant change parameter of that.
How can i do that?
Main.blade.php:
<div class="col-md-6">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#AddGorohkary">add</button>
</div>
<div class="row" >
<div class="col-md-12" >
<ul class="horizontal-slide" dir="ltr" >
#include("Panel")
</ul>
</div>
</div><!-- row -->
Panel.blade.php:
<li class="col-md-3" >
<div class="panel panel-primary" >
<div class="panel-heading">
<div class="row">
<div data-toggle="tooltip" data-placement="bottom" title="حذف این گروه کاری" class="col-md-1 col-sm-1 col-xs-1 col-lg-1 col-md-offset-1">
<button onclick=" remove_entry($(this).parent().parent().parent().parent());" style="color: black;" type="button" class="close" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div data-toggle="tooltip" data-placement="bottom" title="تنظیمات" class="col-md-1 col-sm-1 col-xs-1 col-lg-1">
<span data-toggle="modal" data-target="#SettingModal" dir="rtl" style="color: black;" class=" glyphicon glyphicon-cog " aria-hidden="false"></span>
</div>
<div data-toggle="tooltip" data-placement="bottom" title="باز کردن صفحه گروه کاری" class="col-md-1 col-sm-1 col-xs-1 col-lg-1">
<a style="color: black;" href='/SpecialGoruhKary'><span class='glyphicon glyphicon-export' aria-hidden="false"></span></a>
</div>
<div data-toggle="tooltip" data-placement="bottom" title="اضافه کردن دانش آموز جدید" class="col-md-1 col-sm-1 col-xs-1 col-lg-1">
<span style="color: green;" class="glyphicon glyphicon-plus" aria-hidden="false"></span>
</div>
<div class="col-md-5 col-sm-5 col-xs-5 col-lg-5">
<span>#yield("GorohKarbariName")</span>
</div>
</div>
</div>
<div class="panel-body" style=" overflow-y: scroll;" >
#yield("table_body")
</div>
</div>
</li>
<!---------------------------------- Modal ---------------------------------------------------->
<div id="SettingModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div dir="rtl" class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title ">مشخصات این گروه کاری</h4>
</div>
<div class="modal-body">
<form dir="rtl" class="form-horizontal" action="{{ url('image-upload') }}" enctype="multipart/form-data" method="post" id="viewGorohkaryForm" >
{{ csrf_field() }}
<!-- Text input-->
<div class="form-group">
<div class="col-md-5 col-md-offset-3 inputGroupContainer">
<div dir="ltr" class="input-group">
<input dir="rtl" id="GorohKaryName" name="GorohKaryName" placeholder="اسم گروه کاری" class="form-control" type="text">
<span class="input-group-addon"><i class="glyphicon glyphicon-tag"></i></span>
</div>
</div>
<label for="GorohKaryName" class="col-md-2 control-label">اسم گروه کاری <span style="color: red">*</span> </label>
</div>
<!-- Text input-->
<div class="row col-md-offset-3">
<div class="form-group col-md-3">
<div class=" inputGroupContainer">
<div class=" clockpicker" data-placement="left" data-align="top" data-autoclose="true">
<div dir="ltr" class="input-group">
<input id="ValidTime" type="text" class="form-control" value="08:00">
<span class="input-group-addon">
<span class="glyphicon glyphicon-time"></span>
</span>
</div>
</div>
</div>
</div>
<div class="form-group col-md-4 ">
<div class=" inputGroupContainer">
<div dir="ltr" class="input-group col-md-offset-1">
<select style="direction: rtl;" class="form-control" id="day" name="day" required="required">
<option value="" data-hidden="true">روز هفته</option>
<option value="0">شنبه</option>
<option value="1">یکشنبه</option>
<option value="2">دوشنبه</option>
<option value="3">سه شنبه</option>
<option value="4">چهارشنبه</option>
<option value="5">پنجشنبه</option>
<option value="6">جمعه</option>
</select>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class="form-group col-md-2">
<div class=" inputGroupContainer">
<div dir="ltr" class="input-group">
<button type="button" class="btn btn-info btn-sm">
<span class="glyphicon glyphicon-plus"></span>
</button>
</div>
</div>
</div>
<label for="ValidTime" class="col-md-2 control-label" >زمان معتبر<span style="color: red">*</span> </label>
</div><!-- row clock-->
</form>
</div><!---modal body--->
<div class="modal-footer">
<button id="CreateNewGorohkary" type="submit" class="btn btn-warning" data-dismiss="modal">ذخیره <span class="glyphicon glyphicon-save"></span></button>
</div>
</div><!-- modal content-->
</div>
</div>
You can use of Including Sub-Views section of this link.
In that link you can see how send parameter to an include page.

How to display a popup when clicks the link in the header?

In my header provide a link for adding new client. When click the add client link display a popup window that contain a textbox and a submit button.When i click the link display popup window fully fade in(shaded) and not display the label
Whats wrong here?
header
<a data-hover="dropdown" data-close-others="true" data-toggle="modal" class="dropdown-toggle" href="#addClientPop" <?php if($home_index== 1) { ?> class="active" <?php } ?>></span>
Add Client<span class="arrow"></span>
</a>
<div id="addClientPop" class="modal hide fade" tabindex="-1" data-width="760">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h3>Add Client</h3>
</div>
<div class="modal-body">
<div class="scroller" style="height:75px" data-always-visible="1" data-rail-visible1="1">
<div class="row-fluid">
<div class="control-group">
<label class="control-label">Client Name</label>
<div class="controls">
<input id="client_name" name="client_name" class="client_box" type="text" class="form-control" required >
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button onClick="submit_client();" type="button" class="btn blue">Submit</button>
</div>
</div>
This is your solution i have worked well
<a data-hover="dropdown" data-close-others="true" data-toggle="modal" class="dropdown-toggle active" href="#addClientPop" >
Add Client<span class="arrow"></span>
</a>
<div id="addClientPop" class="modal fade" tabindex="-1" aria-hidden="true">
<div class="modal-dialog ">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h3>Add Client</h3>
</div>
<div class="modal-body">
<div class="scroller" style="height:75px" data-always-visible="1" data-rail-visible1="1">
<div class="row-fluid">
<div class="control-group">
<label class="control-label">Client Name</label>
<div class="controls">
<input id="client_name" name="client_name" class="client_box" type="text" class="form-control" required >
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button onClick="submit_client();" type="button" class="btn blue">Submit</button>
</div>
</div>
</div>
</div>
In your code what i have noticed that you have closed </span> tag in <a> and if($home_index==1) then class attribute is going to be add two times.
It should be like:
<a data-hover="dropdown" data-close-others="true" data-toggle="modal" class="dropdown-toggle <?php if($home_index== 1) { echo 'active';}?>" href="#addClientPop">Add Client <span class="fa fa-arrow-down"></span> </a>
<li>
<a data-hover="dropdown" data-close-others="true" data-toggle="modal" class="dropdown-toggle active" href="#addPop" >
Add Client<span class="arrow"></span>
</a>
<div id="addPop" class="modal fade" tabindex="-1" aria-hidden="true">
<div class="modal-dialog ">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h3>Add Client</h3>
</div>
<div class="modal-body">
<div class="scroller" style="height:75px" data-always-visible="1" data-rail-visible1="1">
<div class="row-fluid">
<div class="control-group">
<label class="control-label">Client Name</label>
<div class="controls">
<input id="market_price" name="market_price" class="client_box" type="text" class="form-control" required >
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button onClick="submit_price();" type="button" class="btn blue">Submit</button>
</div>
</div>
</div>
</div>
</li>

Categories