1
votes

Route file:-

Route::get('/Observation/{type}/list/{status}', 'ObservationController@index')->name('list_observation');

Current URL : localhost:8088/hse/public/Observation/status/list/2

Controller:

protected $type ;
    protected $status ;
    public function __construct(Request $request)
    {
        $this->middleware('auth')->except('getBuildings');
        $this->status = Route::current()->parameter('status');
        $this->type = Route::current()->parameter('type');
    }

    public function index()
    {
        if ($this->status == 'all'){
        $observations = Observation::all();
        }
        else {
            $observations = Observation::where($this->Type(),$this->status)->get();
        }
       return view('observations._list')->with('observations',$observations);
    }
    public function Type(){
        switch ($this->type){
            case 'building':
                $this->type = 'building_id';
                break;
            case 'status':
                $this->type = 'status_id';
                break;
        }
        return $this->type;


    }

Error showing: Missing required parameters for [Route: list_observation] [URI: Observation/{type}/list/{status}]. (View:

When i remove the $this->Type() method in query line , error disappear.

The return value for $this->Type() method is : status_id

Which is the right DB column name.

2
What is the URL you're accessing your controller with? - jedrzej.kurylo
localhost:8088/hse/public/Observation/status/list/2 ,, and also same error is showing in other routes not related to that controller - Q8root
Set two parameters as arguments to index($type, $status) method. Check route parameters. - Tpojka
@user2873860 Maybe somewhere in the view where you are trying to use that url, you does not put both values in the url. - ako
That might be it.Check places where you generate that URL, make sure you pass all required arguments - jedrzej.kurylo

2 Answers

1
votes

Maybe somewhere in the view or where you are generating that URL you does not pass all required arguments to the route.

0
votes

We had to do this while migration from laravel 5.1 to 5.6

While searching for a solution how to carefully fix this problem, we simply replaced every slug from {SLUG} to {SLUG?} instead of fixing every problem where it occurred.

We are using Route-Annotation (https://github.com/LaravelCollective/annotations). So our replacement-REGEX looked like this:

  • Search: (@\b(?:Post|Get|Put|Delete|Update)\b.*\{)([^?"]*)(\}.*\n)
  • Replace: $1$2?$3

Somebody looking for this specific problem, would need to adjust the regex. Maybe someone can fix this in the comments.

This is not a pretty solution, but it does the job. Maybe this helps anyone in the future.