divHelper11 divHelper11 - 1 year ago 150
PHP Question

Laravel 5.2 model static functions use

I probably do not understand how these static functions work.

In my company's project they just create a public static function in any model and then they are using it this way

. I think their models and controllers look similar to mine.

Now, I am training programming at home, I have created a Character model in App directory. Then I tried to use it the same way in CharacterController but it says:

FatalErrorException in CharacterController.php line 18: Class 'App\Http\Controllers\Character' not found

For me it looks like Laravel was searching for the static function in controller instead of my model.

My model:


namespace App;

use app;
use Illuminate\Database\Eloquent\Model;

class Character extends Model
protected $table = 'character';

public static function insertCharacterRace($race){
DB::insert('INSERT INTO `character` VALUES `race` = ?', array($race));


My controller:


namespace App\Http\Controllers;

use App\Http\Requests;
use Illuminate\Http\Request;
use App;

class CharacterController extends Controller

public function raceSelected($race){


Answer Source

In your controller change this:

use App;

To this:

use App\Character;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download