0

The error I got is this:

FatalErrorException in searchController.php line 148: syntax error, unexpected 'public' (T_PUBLIC)

Here is my code:

    if($criteria == 'courses'){

    //return redirect()->back();    <-- if I uncomment this code and remove the code from "$result" all the way down to the second "return view" code, I don't get an error.
    $result=schools::whereRaw("MATCH(undergradcourses,postgradcourses) AGAINST('$searchItem')")->where('status','')->get();

    if(count($result)>0){

    $count=count($result);

    return view('schools', array('result' => $result))->with(array('searchItem'=>$searchItem,'criteria'=>$criteria,'count'=>$count))->with('searchItem',$searchItem);   

    }

    else{

        return view('schools')->with(array('msg'=>'Oops, No result found','count'=>'0','searchItem'=>$searchItem,'criteria'=>$criteria));

    }

    }



    //sort search

    public function sortsearch(Request $request){ <-- this is line 148

If you can see from the comments I made above, if I uncommented return redirect()->back(); and removed the rest of the code from $result to the else code, no error displays and page works fine.

I copied this code from the code above it (it focuses on requests that deal with schools) which works fine:

    public function postsearch(Request $request){

    $searchItem=$request['searchItem'];

    $criteria=$request['criteria'];

    if($criteria == 'schools'){

    $result=schools::whereRaw("MATCH(name,describtion) AGAINST('$searchItem')")->where('status','')->get();

    if(count($result)>0){

    $count=count($result);

    return view('schools', array('result' => $result))->with(array('searchItem'=>$searchItem,'criteria'=>$criteria,'count'=>$count))->with('searchItem',$searchItem);   

    }

    else{

        return view('schools')->with(array('msg'=>'Oops, No result found','count'=>'0','searchItem'=>$searchItem,'criteria'=>$criteria));

    }

    }
halfer
  • 19,824
  • 17
  • 99
  • 186
Thomas
  • 73
  • 8
  • Did you close previous function tag? – Kacper Feb 10 '18 at 13:40
  • You have an "if" condition that is not closed properly, missing a curly brace OR you're missing a curly brace to close the function. Try using an IDE, it will highlight minor errors such as these. – user1453870 Feb 10 '18 at 13:40
  • Or try al least __correct__ indentation for nested structures. – u_mulder Feb 10 '18 at 13:44
  • @user1453870 I am. Using Sublime Text 3. – Thomas Feb 10 '18 at 13:55
  • @Thomas In sublime, you can actually see the pair or brackets/curly braces, place your cursor just before a closing bracket/brace, and you'll see the opening one being highlighted also (highlight in this case is the braces being underlined) – user1453870 Feb 10 '18 at 14:14
  • The problem was I was missing a bracket. The else statement had its own bracket. Needed an additional bracket to close out the function. Just needed additional time (and input from the internet) to figure it out. – Thomas Feb 10 '18 at 14:34

0 Answers0