如何解决我想在计数 =1 时禁用删除按钮,当计数等于 0 时我想启用删除按钮
@extends('layouts.app')
@section('content')
<table class="table">
<thead>
<tr>
<th scope="col">id</th>
<th scope="col">PRODUCT_NAME</th>
<th scope="col">PRODUCT_DESCRIPTION</th>
<th scope="col">PRODUCT_IMAGE</th>
<th scope="col">PRODUCT_CODE</th>
<th scope="col">CATEGORY_NAME</th>
<th scope="col">OPERATION</th>
</tr>
</thead>
<tbody> @foreach ($products as $product ) <tr>
<td scope="col">{{ $product->id}}</td>
<td scope="col">{{ $product->Product_name}}</td>
<td scope="col">{{ $product->Product_description}}</td>
<td scope="col">{{ $product->Product_image}}</td>
<td scope="col">{{ $product->Product_code}}</td>
<td scope="col">{{ $product->Category_id}}</td>
<td scope="col">
<form action="{{route('store.product.destroy',$product->id)}}" method="POST"
onsubmit="return confirm('Are you sure want to delete it')"> <a class="btn btn-info"
href="{{route('store.product.edit',$product->id)}}">EDIT</a> <a class="btn btn-warning"
href="{{ route('store.product.show',$product->id)}}">SHOW</a> @csrf @method('DELETE') <button
type="submit" class="btn btn-danger" id="delete">DELETE</button> </form>
</td>
</tr> @endforeach </tbody>
</table>
<form action="{{route('store.product.create')}}" method="GET">
<div class="form-group"> <button type="submit" class="btn btn-primary">Create</button> </div>
</form>
@endsection
这是我的控制器页面:
<?PHP
namespace App\Http\Controllers;
use App\Models\Category;
use App\Models\Product;
use Illuminate\Http\Request;
class ProductController extends Controller {
/**
* display a listing of the resource.
* @return \Illuminate\Http\Response
*/
public function index() {
$data=array( 'products' =>Product::all() );
return view('product.index',$data);
}
/**
* Show the form for creating a new resource. *
* @return \Illuminate\Http\Response
*/
public function create() {
$category=array( 'category' =>Category::all() );
return view('home',$category);
}
/**
* Store a newly created resource in storage.
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $req) {
$product =new Product();
$product->Product_name=$req->input('Product_name');
$product->Product_description= $req->input('Product_description');
$product->Product_image= $req->file('Product_image')->store('Product_image');
$product->Product_code= $req->input('Product_code');
$product->Category_id= $req->input('Category_id');
$product->save();
return redirect()->route('store.product.index',['products'=>$product->id]);
}
/**
* display the specified resource.
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id) {
$category=array( 'category' =>Category::all() );
return view('product.show',$category,['product' => Product::findOrFail($id)]);
}
/**
* Show the form for editing the specified resource.
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id) {
$category=array( 'category' =>Category::all() );
return view('product.edit',['product'=>Product::FindOrFail($id)]);
}
/**
* Update the specified resource in storage.
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request) {
$product=Product::find($request->id);
$product->Product_name=$request->input('Product_name');
$product->Product_description= $request->input('Product_description');
$product->Product_image= $request->input('Product_image','public');
$product->Product_code= $request->input('Product_code');
$product->Category_id= $request->input('Category_id');
$product->save();
return redirect()->route('store.product.index',['product'=> $product->id]);
}
/**
* Remove the specified resource from storage.
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) {
$product = Product::findOrFail($id);
$product->delete();
echo ("User Record deleted successfully.");
return redirect()->route('product.index');
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。