Please can anyone help me figure this out, I have been trying to get the view, edit and delete buttons on a shipment table on my website page to display a view for the respective shipment buttons when clicked. But the view has to be for the each shipment, where the link is placed in the table row, that is each set of row buttons should display a view for the particluar shipment data on the table row.
Here is my blade template to display the all shimpment(s) table:
<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"></a></td>
<td class="no-space"></td>
<td class="no-space"></td>
<td class="shipment-status pending"></td>
<td class="shipment-type default"></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>
Here is the home controller, which displays the all shipment(admin-index) page/view:
<?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'));
}
}
Here is what I have tried in the shipment controller for displaying a single views using the buttons on the table. But I know it is no where near what I am supposed to do:
<?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)
{
}
Here are my routes:
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');
How do I create a relationship, which can be used for getting a particluar shipment when its respective view, edit and delete buttons are clicked? I have an unique id and tracking_code columns for each shipment on my db table. How do use them as the relationship?
Aucun commentaire:
Enregistrer un commentaire