S
S
Scronheim2017-01-26 18:50:41
Laravel
Scronheim, 2017-01-26 18:50:41

Strange behavior of routes in laravel 5.3?

Good afternoon, there is a route
Route::get('/search','[email protected]');
There is a search function in the ArchiveController controller

protected function search(Request $request){
        $search = $request->search;
        $style_s = $request->style;
        $country_s = $request->country;
        $year = $request->year;
        $author = $request->author;

        $albums_count = DB::table('archive')->count();
        $albums = DB::table('archive')->when($search, function ($query) use ($search) {
            return $query->where('artist', $search);
        })->when($style_s, function ($query) use ($style_s) {
            return $query->where('style', $style_s);
        })->when($country_s, function ($query) use ($country_s) {
            return $query->where('country', $country_s);
        })->when($year, function ($query) use ($year) {
            return $query->where('year', $year);
        })->when($author, function ($query) use ($author) {
            return $query->where('author', $author);
        })->orwhere('album', $search)->orderby('id',false)->paginate(9) ;
        $country = Country::all('name')->sortBy('name');
        $year = Year::all('name')->sortByDesc('name');
        $style = Style::all('name')->sortBy('name');

        return view('albums.index', ['albums' => $albums, 'albums_count' => $albums_count, 'style' => $style, 'country' => $country, 'year' => $year]);
    }

And view
<form class="form-inline" method="get" id="search" action="/search">

In this scenario, everything works great, but it's worth changing the view to
<form class="form-inline" method="get" id="search" action="/albums/search">

and route to
Route::get('/albums/search','[email protected]');

It is no longer looking for anything. What is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Perin, 2017-01-26
@scronheim

Maybe because you have another route Route::get('/albums/{any} ', '[email protected]'); ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question