I need to use a Model function in a controller but get the above error:
Non-static method App\Models\Employee::getEmployeeName() should not be called statically, assuming $this from incompatible context
My Model:
<?php namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Employee extends Model
{
protected $table = ‘BLABLA’;
public function getEmployeeName()
{
if ($this->EmployeeName){
return "{$this->EmployeeName}";
}
return null;
}
}
My controller:
use Auth;
use DB;
use App\Models\Bookings;
use App\Models\User;
use App\Models\Employee;
use Illuminate\Http\Request;
class BookingsController extends Controller {
public function postBooking(Request $request){
$employee=Employee::getEmployeeName()->get();
dd($employee);
}
}