Por favor, ¿alguien puede ayudarme a resolver esto? He estado tratando de obtener los botones de visualización, edición y eliminación en una tabla de envío en la página de mi sitio web para mostrar una vista de los botones de envío respectivos cuando se hace clic. Pero la vista debe ser para cada envío, donde el enlace se coloca en la fila de la tabla, es decir, cada conjunto de botones de fila debe mostrar una vista de los datos de envío en particular en la fila de la tabla.

Aquí está mi plantilla de hoja para mostrar la tabla de todos los cambios:

<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>

Aquí está el controlador doméstico, que muestra la página / vista de todos los envíos (índice de administración):

<?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'));
        
      
    }
}

Esto es lo que probé en el controlador de envío para mostrar vistas únicas usando los botones de la mesa. Pero sé que no está ni cerca de lo que se supone que debo hacer:

<?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)
    {
        
    }

Aquí están mis rutas:

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');

¿Cómo creo una relación, que se puede utilizar para obtener un envío particular cuando se hace clic en sus respectivos botones de visualización, edición y eliminación? Tengo una identificación única y columnas de código de seguimiento para cada envío en mi tabla de base de datos. ¿Cómo los utilizo como relación?

0
Darrly Smith 25 ago. 2020 a las 14:43

1 respuesta

La mejor respuesta

En su foreach loop ya que tiene una columna para delete y edit para que pueda tener algo así. solo lo hago por edit

Vista de hoja

<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');

controlador

public function edit(Shipment $shipment){
return view('shipmentview',compact('shipment'));
}

Puede seguir lo mismo para eliminar, así como a continuación.

vista de hoja

<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');

controlador

public function delete(Shipment $shipment){
$shipment->delete();
return back();
}
0
Naveed Ali 25 ago. 2020 a las 13:13