问题描述
请任何人帮助我解决这个问题,我一直在尝试获取我网站页面上货运表上的视图,编辑和删除按钮,以在单击时显示各个货运按钮的视图。但是视图必须针对链接位于表行中的每个货件,即每组行按钮应在表行中显示特定货件数据的视图。
这是我的刀片模板,用于显示所有碎屑表:
<table id="shipment-list" class="table table-hover table-sm">
<thead>
<tr>
<th class="form-check">
<input class="form-check-input " id="wpcfe-select-all" type="checkBox">
<label class="form-check-label" for="materialChecked2"></label>
</th>
<th>Tracking Number</th>
<th class="no-space">Shipper Name</th>
<th class="no-space">Receiver Name </th>
<th>Status</th>
<th>Shipment Type</th>
<th class="text-center">View</th>
<th class="text-center">Print</th>
<th class="text-center">Update</th>
<th class="text-center">Delete</th>
</tr>
</thead>
<tbody>
@if(count($shipment) >0)
@foreach($shipment as $shipment)
<tr id="shipment-2928" class="shipment-row pending">
<td class="form-check">
<input class="wpcfe-shipments form-check-input " type="checkBox" name="wpcfe-shipments[]" value="2928" data-number="MSD076941-CARGO">
<label class="form-check-label" for="materialChecked2"></label>
</td>
<td><a href="#" class="text-primary font-weight-bold" name="tracking_code">{{$shipment->tracking_code }}</a></td>
<td class="no-space">{{$shipment->sender_name }}</td>
<td class="no-space">{{$shipment->receiver_name }}</td>
<td class="shipment-status pending">{{$shipment->status }}</td>
<td class="shipment-type default">{{$shipment->shipment_type }}</td>
<td class="text-center">
<a href="/single" title="View">
<i class="fa fa-list text-success"></i>
</a>
</td>
<td class="text-center print-shipment">
<div class="dropdown">
<!--Trigger-->
<button class="btn btn-default btn-sm dropdown-toggle m-0 py-1 px-2 waves-effect waves-light" type="button" id="dropdownPrint" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"><i class="fa fa-print"></i></button>
<!--Menu-->
<div class="dropdown-menu dropdown-primary" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(0px,38px,0px);" x-out-of-boundaries="">
<a class="dropdown-item print-invoice py-1" data-id="2928" data-type="invoice" href="#">Invoice</a>
<a class="dropdown-item print-label py-1" data-id="2928" data-type="label" href="#">Label</a>
<a class="dropdown-item print-waybill py-1" data-id="2928" data-type="waybill" href="#">Waybill</a>
</div>
</div>
</td>
<td class="text-center wpcfe-action">
<a href="#" title="Update">
<i class="fa fa-edit text-info"></i>
</a>
</td>
<td class="text-center">
<a href="#" class="wpcfe-delete-shipment" data-id="2928" title="Delete"><i class="fa fa-trash text-danger"></i></a>
</td>
</tr>
@endforeach
@else
<tr>
<td colspan="6">
<strong>No Users Found !!!</strong>
</td>
</tr>
@endif
</tbody>
</table>
</div>
<?PHP
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Shipment;
use DB;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$page_title = "Admin Dashboard";
$shipment = Shipment::latest()->get();
return view('home',compact('shipment','page_title'));
}
}
这是我在装运控制器中尝试使用表上的按钮显示单个视图的方法。但是我知道这离我应该做的事不远:
<?PHP
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use App\Shipment;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\MessageBag;
class ShipmentController extends Controller
{
/**
* Create a new user instance after a valid registration.
*
* @param Request $request
* @return \App\Shipment
*/
protected function store(Request $request)
{
$shipment = new Shipment();
$data = $this->validate($request,[
'sender_name' => 'required|string|max:255','sender_email' => 'required|string|email|max:255','receiver_email' => 'required|string|email|max:255','sender_address' => 'required|string','estimated_Date' => 'required||date|after:today','shipment_type' => 'required|string|max:255','content' => 'required|string|max:255','receiver_name' => 'required|string|max:255','receiver_address' => 'required|string|max:255','sender_country' => 'required|string|max:255','sender_telephone' => 'required|string|max:255','comments' => 'required|string|max:255','receiver_telephone' => 'required|string|max:255','receiver_country' => 'required|string|max:255','package_weight' => 'required|string|max:255',]);
$shipment->sender_name = $request->input('sender_name');
$shipment->receiver_email= $request->input('receiver_email');
$shipment->sender_email= $request->input('sender_email');
$shipment->sender_address= $request->input('sender_address');
$shipment->estimated_Date= $request->input('estimated_Date');
$shipment->shipment_type= $request->input('shipment_type');
$shipment->content= $request->input('content');
$shipment->receiver_name= $request->input('receiver_name');
$shipment->receiver_address= $request->input('receiver_address');
$shipment->sender_country= $request->input('sender_country');
$shipment->sender_telephone= $request->input('sender_telephone');
$shipment->comments= $request->input('comments');
$shipment->receiver_telephone= $request->input('receiver_telephone');
$shipment->receiver_country= $request->input('receiver_country');
$shipment->package_weight= $request->input('package_weight');
$shipment->tracking_code = strtoupper(Str::random(20));
$shipment->save();
return redirect('/index')->with('Success','Your Shipment has been created');
}
public function tracking(Request $request){
$this->validate($request,[
'tracking_code' => 'required|max:25',]);
$shipment = Shipment::where('tracking_code',$request->input('tracking_code'))->first();
if ( $shipment == null)
{
return redirect('/shipment/track')->with('error','Incorect Tracking Number');
}
else{
return view('shipment.single')->with('shipment',$shipment);
}
}
public function single(request $request ){
$page_title = "view shipment";
$tracking_code = Shipment::get()->tracking_code;
$shipment= Shipment::where('tracking_code',$tracking_code)->first();
return view('shipment.single',compact('tracking_code','shipment','page_title'));
}
/**
* Show the form for editing the specified resource.
*
* @param int $request
* @return \Illuminate\Http\Response
*/
public function edit(Request $request)
{
$shipment = Shipment::where($shipment->tracking_code );
//check for Admin user
if (Gate::allows('isAdmin')) {
return view('shipment.edit')->with('shipment',$shipment);
}else {
return redirect('/home')->with('error','Unauthorized Page');
}
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request,$id)
{
}
这是我的路线:
Route::get('/single','ShipmentController@single')->name('single');
Route::get('/shipment/createnew','PagesController@createnew');
Route::Post('/shipment/storenew','ShipmentController@store')->name('storenew');
Route::get('/shipment/edit','ShipmentController@edit')->name('edit');
Route::Post('/tracking','ShipmentController@tracking')->name('tacking');
Auth::routes();
Route::get('/home','HomeController@index')->name('home');
如何创建一个关系,当单击其各自的查看,编辑和删除按钮时,该关系可用于获取特定的装运? 我的数据库表中的每个货件都有唯一的id和tracking_code列。如何将它们用作关系?
解决方法
在您的foreach loop
中,因为您有delete
和edit
的一列,所以可以有类似的内容。我只为edit
刀片视图
<td class="text-center">
<a href="{{route('shipment.edit',$shipment->id)}}" class="wpcfe-edit-shipment" data-id="2928" title="Edit"><i class="fa fa-edit text-primary"></i></a>
</td>
web.php
Route::get('/shipment/edit/{shipment}','ShipmentController@edit')->name('shipment.edit');
控制器
public function edit(Shipment $shipment){
return view('shipmentview',compact('shipment'));
}
您也可以按照以下步骤进行删除。
刀片视图
<td class="text-center">
<a href="{{route('shipment.delete',$shipment->id)}}" class="wpcfe-edit-shipment" data-id="2928" title="Delete"><i class="fa fa-trash text-danger"></i></a>
</td>
web.php
Route::get('/shipment/{shipment}/delete','ShipmentController@delete')->name('shipment.delete');
控制器
public function delete(Shipment $shipment){
$shipment->delete();
return back();
}