Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
131 views
in Technique[技术] by (71.8m points)

Dynamic url laravel

I have an app that search for places in citys.

I have this route

  Route::get('s/{where}/{places}', 'SearchController@places')->name('search');

The SearchController

class SearchController extends Controller{

public function places(Request $request, $where, $places)
{   
    $where = $request->where;
 
    if($places == 'places'){
        return view('search.places', ['where' => $where]);
    }else{
         abort('404');
    }
 }
}

I also have tried with

   ->with()

The form submission to search

 <form action="{{ route('search' ,  ['where', 'places']) }}" method="get">

I am getting something like this:

http://localhost/s/where/places?where=Paris

What i want is

http://localhost/s/paris/places

when it shoul replace the where in the url and not add where after the question mark!

Thanks for help

question from:https://stackoverflow.com/questions/65849331/dynamic-url-laravel

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Based on how you set your route you need to set as below:

<form action="{{ route('search' ,  ['where' => 'paris', 'places' => 'places']) }}" method="get">

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...