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.

1
  • Please scroll all the way down to see the show function. Commented Apr 10, 2020 at 7:38

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

I have tried adding the id on show route but then I get an error 404 not found
@ItsCharlie4real Can you give an example of the url you're using?
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.