I'm currently developing a CMS using PHP Laravel (5.4) based on an existing ASP.NET MVC version I've made in the past. Since most of the ASP.NET version is written in JS, I'm trying to reuse the most I can in the newer Laravel version I'm developing. I have already translated most of the C# code to PHP, thanks to Laravel's similarities with ASP.NET MVC architecture, this was somewhat straightforward.
Currently I'm facing a issue trying to call a controller action from within a view that will in-turn render a partial view. In the ASP.NET MVC version I've accomplished this using a Html.RenderAction
helper.
ASP.NET MVC Example:
<div>
@{Html.RenderAction("Controller", "Action");}
</div>
I want know if there is any alternative to the Html.RenderAction
helper that I can use to accomplish this task.
I've search the interwebs and Laravel's documentation, and from what I was able to find, View Composers seem to be closest alternative. Unfortunately, I didn't find any example that could resolve my issue.
@Farrukh suggested using View Composers and it does actually work as intended. The problem is that I will need to add a View Composer to the AppServiceProvider for every partial view I want to render.
I found another solution that allows me to call an action from a view and render a partial view:
<?php echo \App\Http\Controllers\PageController::listAll(); ?>
But this solution doesn't seem very clean.