Reputation: 3250
what is the best practice to load a view.
documentation is saying load view here https://laravel.com/docs/5.7/views
following is my code:
if (isset($results['status'])) {
$error [] = $results['msg'];
$request->session()->flash('message.level', 'danger');
$request->session()->flash('message.content', $error);
} else {
if (view()->exists('import.device.results')) {
echo view('import.device.results', compact('results'));
exit;
}
}
when i use
echo view('import.device.results', compact('results'));
it takes a second and when i use
return view('import.device.results', compact('results'));
it takes like 10 seconds
my view file:
@extends('layouts_blue.master')
@section('content')
<!--content-->
<script language="JavaScript">
</script>
<div class="container content-body table-responsive" id="no-more-tables1">
@if(session()->has('message.level'))
<div class="alert alert-{{ session('message.level') }} import-device-error">
<ul class="fa-ul">
@foreach (session('message.content') as $error)
<li>{!! $error !!}</li>
@endforeach
</ul>
</div>
@endif
</div>
</div>
@stop
Upvotes: 3
Views: 925
Reputation: 15135
return
If called from within a function, the return
statement immediately ends execution of the current function, and returns
its the value of the function called. passing a value to another function or variable.
echo
outputs a value one or more
echo
prints the value so you can read it.
return
returns the value to save in variable.
In laravel same you can store view in variable by return
.
In middleware return
used to stop a execution or pass to the next function
In return
u can return as you type like Json or object or many array with value.
Upvotes: 2
Reputation: 35337
Laravel performs a lot of necessary actions after it gets the response from your controller. By exiting from your controller, you are terminating the request in the middle of its lifecycle:
Upvotes: 5