There’s nothing ready for what I can verify, but there are ways to execute:
Minimal example
Controller
<?php namespace App\Http\Controllers;
use Illuminate\Http\Request;
class SortController extends Controller
{
public function index()
{
return view('sort');
}
public function trecho(Request $request)
{
$url = $request->fullUrl();
return view('trecho', ['url' => $url]);
}
}
Routes.php
Route::get('/sort', ['as' => 'sort.index', 'uses' => 'SortController@index']);
Route::get('/sort/trecho', ['as' => 'sort.trecho', 'uses' => 'SortController@trecho']);
View
Sort
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="robots" content="noindex, nofollow">
<meta name="googlebot" content="noindex, nofollow">
<title>View Sort</title>
</head>
<body>
<h1>Sort</h1>
{!! app(App\Http\Controllers\SortController::class)->trecho(app('request')) !!}
</body>
</html>
In the controller
there are two methods one that will start and the other that will be called by View
sort.blade.php
. In his View
call the command:
{!! app(App\Http\Controllers\SortController::class)->trecho(app('request')) !!}
that the execution will play its part in bringing the View
generated.
Can also be generated a blade extension
As follows, open the file app\Providers\ServiceProvider.php
and import the namespace
: Illuminate\Support\Facades\Blade;
and within the method boot
add the following code to create a new blade
for your project:
public function boot()
{
Blade::directive('action', function($expression) {
$vars = explode(',', $expression);
$ctrl_string = trim(array_shift($vars));
$meth_string = trim(array_shift($vars));
$ctrl = app($ctrl_string);
$items = array_map(function ($var){
return eval("return $var;");
}, $vars);
$view = (is_array($items) && count($items) > 0)
? call_user_func_array(array($ctrl, $meth_string), $items)
: call_user_func(array($ctrl, $meth_string));
return "<?php echo '".$view."'; ?>";
});
}
In the View
call as follows:
@action(App\Http\Controllers\SortController,trecho,app('request'))
References:
Your doubt is causing new ones! Are you willing to work with ajax? or are you willing to carry a View inside each other by Action? if it could edit and try to explain in more detail, it was not very clear
– novic
I’m looking to load one view into the other by the action
– Bruno Assis de Tassis
Post this View? with this call! Why so with
@include
I would, so I need to know what you really want.– novic
It’s close to that, but I don’t think the technology exists in the basement yet. When I was programming in ASP.NET I had a Helpers in Razor which is the ASP.NET Engine Template that generated a partial view for me, where he called it from a controller action. =/
– Bruno Assis de Tassis
I understand I don’t think there is but I’ll take a look.
– novic
Thanks so much for your cooperation!
– Bruno Assis de Tassis
Place a new edition with a
blade
created... much like what you said on Asp.net– novic