0

I am working on a Laravel project which runs fine on my Virtual box ubuntu 14.04 on a Mac Platform. It is very difficult to keep up with changes as rsync files etc etc, so I decided to move the app into my Mac Platform.

When I do this i always get the following error:

{"error":{"type":"ErrorException","message":"The use statement with non-compound name 'DB' has no effect","file":"\/Users\/user\/data\/folder\/app\/controllers\/CampaignsController.php","line":3}}

My CampaignsController.php looks like this:

<?php

  use \DB;
  use \Auth;
  use \Validator;
  use \Event;
  .......

If I comment them out the app starts running. The only problem is when i need to commit changes, i need to remove the commented out lines and the re-comment them out for the app to run.

Is there any other way to fix this issue and why would the app run fine in a linux environment but not under a Mac Os environment?

Leon
  • 1,262
  • 3
  • 20
  • 41
  • Your `CampaignsController.php` file needs a namespace declaration. Typically in Laravel 5 that'd be `namespace App\Http\Controllers;` after the ` – ceejayoz Feb 22 '16 at 01:59
  • Why it does work in A linux VM though? This is what i am trying to understand. – Leon Feb 22 '16 at 02:25
  • I'd wonder if you have different PHP versions on the two. Fix the underlying issue - add a namespace to your controllers. Laravel expects that. – ceejayoz Feb 22 '16 at 02:29
  • I did add a namespace but my controllers all extend a class called AbstructCrudController, which is in the same folder as all controllers `app/controllers/` and after adding `namespace App\Controllers` if says unable to find that Abstract class. I am very new to PHP and Laravel so not sure what is wrong with it. – Leon Feb 22 '16 at 02:41
  • The abstract class will also need a namespace declaration. – ceejayoz Feb 22 '16 at 02:47
  • Are you **sure** you're using Laravel 5? `app/controllers` is the old Laravel 4 file layout. Laravel 5 puts controllers in `app/Http/Controllers` these days – ceejayoz Feb 22 '16 at 02:48
  • I am sorry, I just saw the version is Laravel 4.2 – Leon Feb 22 '16 at 02:51
  • In Laravel 4.2 you don't need the `use` declarations at all to use the main facades. They won't work in Laravel 4's non-namespaced controllers. – ceejayoz Feb 22 '16 at 02:54
  • Yeah i know but why do they work in a Linux environment I do not understand. – Leon Feb 22 '16 at 03:05
  • I'm not sure - maybe there are different versions of PHP on your OSX vs. Linux - but ultimately it doesn't matter. The `use` statements you show in a non-namespaced file are *wrong*. The fix is removing them in your case, or namespacing the controller. – ceejayoz Feb 22 '16 at 03:11
  • Cool, I will see if there are any consequences by removing all those statements. Thanks – Leon Feb 22 '16 at 03:17

0 Answers0