There's nothing ready for what I could check out, but there are ways to do it:
Minimum 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 controller
there are two methods one that will start and the other that will be called by View
sort.blade.php
. In your View
call the command:
{!! app(App\Http\Controllers\SortController::class)->trecho(app('request')) !!}
that execution will play its part in bringing the generated View
.
You can also generate a
blade extension
as follows, open the file
app\Providers\ServiceProvider.php
and import the
namespace
:
Illuminate\Support\Facades\Blade;
and within the
boot
method 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 View
call as follows:
@action(App\Http\Controllers\SortController,trecho,app('request'))