Hello!
Began to study laravel5, and here such a question arose.
I have a controller, an API that responds to ajax requests. But I can not figure out how to connect the desired model, depending on the request.
// Код контроллера namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Message; class ApiController extends Controller { public function index($action){ $messages = Message::count(); $data = array( 'status' => 'success', 'action' => 'action' ); return json_encode($data); } } Here I have one model connected
use App\Models\Message; I can use it, everything is wonderful. But, I will have to take records from different models, how to connect them depending on $ action-a? I do not want to immediately connect 10 models through use
use App\Models\Message; use App\Models\Users; use App\Models\Servers; use App\Models\Caegory; I just don’t know how to do it right, so I’m asking, maybe I’m not doing it right .. Please do not throw slippers :)
withmethod. If not, switch on the action to go through - Alex_01