Wednesday, March 15, 2017

Access model method in controller Laravel

I'm trying to access model method in Ad.php model from the controller in Laravel. I'm trying in the same way as I did in other frameworks, so maybe I'm doing wrong this in Laravel.

My need is to perform some actions before creating or updating the record. These actions are same for both actions, so I want to put logic in model method and call it in controller.

After doing this I just got blank white window with no errors. Why?

My code in Controller:

<?php

namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class AdsController extends Controller {
    public function update(Request $request, $id) {
       $input = Request::all();
       \App\Ad::saveMultiFields($input);
    }
}

Model:

<?php

namespace App;

use Barryvdh\Debugbar\Facade as Debugbar;
use Illuminate\Database\Eloquent\Model as Eloquent;

class Ad extends Eloquent {

    public static function saveMultiFields($input) {
        Debugbar::info($input);
        return true;
    }
}



via Gediminas

Advertisement