Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to pass a variable right through the routes

I get an error when I try passing the var in the routes like this

<a  href="{{route('canvas',['size'=>1000])}}">
...
</a>

I pass the view like this

    public function canvas($size){
        return view('main.canvas')->with($size);
    }

this is the route I use in web.php:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Route::get('canvas',[CustomAuthController::class,'canvas'])->name('canvas');

the error I get is this:
Too few arguments to …\CustomAuthController::canvas(), 0 passed in …\Controller.php on line 54 and exactly 1 expected

It seems the argument isn’t being read for some reason,I tried just route(‘canvas’,1000) but still not working

>Solution :

you should use with() with accessor.

Syntax: ->with('variable-name', $data)


Your route should be.(You should allow property in URL)

Route::get('canvas/{size}', 'CustomAuthController@canvas');

And in controller

public function canvas($size){
    return view('main.canvas')->with('size',$size);
}

In blade you can

{{ $size }}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading