samedi 10 février 2018

Unexpected syntax error in controller file (Laravel)

I have no idea what to title this question. Please don't downvote or close this.

The error I got is this:

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

    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));

    }

    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire