Darama
Darama

Reputation: 3370

As well to use controller inside another controller Laravel?

I have two entities: users, announcements

Eaach user can publish the announcements.

I creted controller AnnouncemetController, where there is method class: my(), that returns notes for current user.

Also I have controller ProfileController that represent current profile user, where I need to show all announcements of user.

For this I tried to reuse controller AnnouncemetController inside ProfileController and call public method my().

use App\Http\Controllers\AnnouncementController;

class ProfileController extends Controller
{
      $my = new AnnouncementController();
      $my->my();
}

Is it well to use such?

Upvotes: 0

Views: 197

Answers (1)

Josh Petitt
Josh Petitt

Reputation: 9579

A Laravel controller maps a uri to an action. In your example, you are using a controller to access data, so this is not the "right thing to do".

Instead use model methods to access the data.

Upvotes: 1

Related Questions