Laravel Parse error: syntax error, unexpected ' public' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)


Laravel Parse error: syntax error, unexpected ' public' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)



I must be blind or something, my Controller is not behaving as expected but I don't see anything wrong in my code. I get "syntax error, unexpected ' public' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)", right after declaring "class ContactController extends Controller {"



My controller:


<?php

namespace AppHttpControllers;

use AppHttpControllersController;
use IlluminateHttpRequest;
use AppContactUS;

class ContactController extends Controller {
   /**
    * Show the application dashboard.
    *
    * @return IlluminateHttpResponse
    */
   public function index(Request $request)
   {
       return view('contactUS');
   }
}



If I do this:


class ContactController extends Controller {
function index(Request $request){
return view('contactUS');
}
}



I get "unexpected ' function' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)"



My model:


<?php

namespace App;

use IlluminateDatabaseEloquentModel;

class ContactUS extends Model
{
public $table = 'contactus';
public $fillable = ['name', 'email', 'message'];
}



My route:


Route::get('contact', [
'as' => 'contact-us',
'uses' => 'ContactController@index'
]);





Does it say in which line the error occures? Which PHP/Laravel version are you using, maybe you are using an old interpreter with a new Laravel version that uses syntax unknown to PHP?
– Tobias K
Jul 1 at 11:49





@TobiasK just updated the question, it's right after declaring the class. It's a controller just like all other controllers in my project, I must have a typo somewhere... or forgot something....
– poashoas
Jul 1 at 11:51






your controller is fine, you sure it's your controller? can i see whoops output ?
– Supun Praneeth
Jul 1 at 12:59





@SupunPraneeth the error is all I get as response, I do notice lots of spaces (tabs) before the word "public". Laravel seems to handle the file totaly the wrong way. Propably the error comes from somewhere else but I have no idea what it could be.
– poashoas
Jul 1 at 13:35






What is in your base class? Add anything there?
– OneLiner
Jul 1 at 16:18









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to add background colour in existing image using Swift?

Moria Casán

How to make file upload 'Required' in Contact Form 7?