1

I have reviewed similar questions but none of the solutions worked for me. I have show view that fetches data from the db which I want to display. I believe I have the right code for my show function on my CtnController but I keep getting this frustrating error. Ctn in this case is a type of form I'm trying to create.

This is my controller.

<?php

namespace App\Http\Controllers;
use App\Ctn;

use Illuminate\Http\Request;
class CtnController extends Controller
{
           /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }
        /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $ctns = Ctn::orderBy('created_at', 'desc')->paginate(5);
        return view('/ctn.index')->with('ctns', $ctns);
    }

    public function create(){
    return view('/ctn.create'); 
    }

    public function store(Request $request){
        $validatedData = $request -> validate([
            'bol' => 'required',
            'carrier' => 'required',
             'address' => 'required',
             'etd' => 'required',
             'eta' => 'required',
             'portload' => 'required',
             'portdischarge' => 'required',

        ]);

        $ctn = new Ctn;
        $ctn->bill_landing = request('bol');
        $ctn->carrier = request('carrier');
        $ctn->address = request('address');
        $ctn->eta = request('eta');
        $ctn->etd = request('etd');
        $ctn->incoterm = request('incoterm');
        $ctn->forwarder = request('forwarder');
        $ctn->ctnref = request('ctnref');
        $ctn->portloading = request('portload');
        $ctn->portdischarge = request('portdischarge');
        $ctn->quantity = request('quantity');
        $ctn->origin_goods = request('origin');
        $ctn->cost_goods = request('cost');
        $ctn->currency = request('currency');
        $ctn->package_type = request('package');

        $ctn->save();
        return redirect('/ctn')->with('success', 'CTN created');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {

        $ctn = Ctn::find($id);
        return view('/ctn.show', compact('ctn'));
    }
}

Below is my show route on web.php file

Route::get('/ctn/show', 'CtnController@show')->name('show');

The show form is just a HTML form.

James Z
  • 12,209
  • 10
  • 24
  • 44

2 Answers2

1

Your show() method excepts an $id, however, you've not specified the value in your route. Change your route definition so that is can accept the id:

Route::get('/ctn/show/{id}', 'CtnController@show')->name('show');

This will assume that you're using a url like:

http://example.com/ctn/show/1

For more information you can view the Route Parameters documentation

Rwd
  • 34,180
  • 6
  • 64
  • 78
0

The $id argument of your show method expects an implicit binding from the route parameters, but your routes does not know any id parameter, therefore it can't be bound to your method.

Shizzen83
  • 3,325
  • 3
  • 12
  • 32