Hello everyone! I'm a Laravel beginner trying to build a REST API for my project. The thing is that I want to inherit all API Controllers from one class so I don't repeat some common functions. Here's my code:
For the APIController.php class:
namespace App\Http\Controllers\API;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
class APIController extends Controller
{
protected $model = null;
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return $this->model::all();
}
.
.
.
This is a child class that inherits from APIController
namespace App\Http\Controllers\API;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class UserController extends APIController
{
public function __construct()
{
$this->model = App\User;
}
}
.
.
.
What i'm trying to do is call UserController from the routes.php file. When UserController gets constructed I'm trying to set the User class on the model attribute of the class. Then I call the methods from UserController defined on APIController
The thing is i'm getting that infamous T_PAAMAYIM_NEKUDOTAYIM error on APIController, in the line that says "return $this->model::all();"
What's the correct way of doing this? Thanks all in advance :)