AO's avatar
Level 1

Route not defined?

Hello.

I'm trying to make a search on the same page in my admin dashboard.

here's what I did in my controller:


  public function search(){

        $q = Input::get ( 'q' );
        if($q != ""){
            $case = Case::where ( 'donation_title', 'LIKE', '%' . $q . '%' )->orWhere ( 'donation_story', 'LIKE', '%' . $q . '%' )->paginate (5)->setPath ( '' );
            $pagination = $case->appends ( array (
                'q' => Input::get ( 'q' )
            ) );
            if (count ( $case ) > 0)
                return view ( 'admin.cases.index' )->withDetails ( $case )->withQuery ( $q );
        }
        return view ( 'admin.cases.index' )->withMessage ( 'No Details found. Try to search again !' );


    }



my route :


 Route::post('/search/case','CasesController@search')->name('admin.search_cases');


my from :


    <div class="container">
        <form action="{{route('admin.search_cases')}}" method="POST" role="search">
            {{ csrf_field() }}
            <div class="input-group">
                <input type="text" class="form-control" name="q"
                       placeholder="Search cases"> <span class="input-group-btn">
                    <button type="submit" class="btn btn-default">
                        <span class="la la-search"></span>
                    </button>
                </span>
            </div>
        </form>
    </div>

Im getting :


Route [admin.search_case] not defined. 

I checked the route list PHP php artisan route:list and I cant see it

PS: I tried to clear the cache and config nothing changed

any idea whats going on here?

0 likes
8 replies
Nakov's avatar

The error shows that you are using a route with a name that does not exists in some view. So try searching your project for usage of 'admin.search_case' and rename that with 'admin.search_cases' as your named route.

1 like
munazzil's avatar

Try with below as well because can't keep any spaces between like condition '%' . $q . '%' change as like below,

$case = Case::where ( 'donation_title', 'LIKE', '%'.$q.'%' )->orWhere ( 'donation_story', 'LIKE', '%'.$q.'%')->paginate (5)->setPath ( '' );
AO's avatar
Level 1

Humm.. the route is not even showing in route:list.

I have the route under a group

Nakov's avatar

Not in route group, I meant that you use route('admin.search_case') in some view hence the error that the route cannot be found, you have misspelled it, you should use route('admin.search_cases') everywhere.

AO's avatar
AO
OP
Best Answer
Level 1

the problem is gone once I updated the app using composer update

Nakov's avatar

Based on your error above, does not make sense that composer fixed that, but I am happy that the problem is gone anyway :)

1 like
rawilk's avatar

@munazzil

because can't keep any spaces between between like condition '%' . $q . '%'

Actually you can because you're not putting the spaces inside the strings being concatenated and for some people it's more readable that way. If you're going to give answers, you really should at least learn the stuff yourself before you give out incorrect information all the time. I'm not trying to be mean but your advice is just terrible. Please stop.

1 like

Please or to participate in this conversation.